NullReferenceException: Object reference not set to an instance of an object
Enemy.Update () (at Assets/Scripts/Enemy.cs:28)
运行的时候控制台不停的输出这个错误
代码的第28行是
rigidbody.MovePosition(Vector2.Lerp(transform.position, targetPosition, smoothing * Time.deltaTime));
请问老师怎么解决?
rigidbody.MovePosition(Vector2.Lerp(transform.position, targetPosition, smoothing * Time.deltaTime));
这里空指针,这里只有一个对象就是rigidbody
原因应该是rigidbody你没有赋值,在start方法里面赋值一下就可以了