我正在学习 Unity 教程。我在尝试检测游戏中的碰撞时遇到了问题。这是错误:
NullReferenceException:未将对象引用设置为对象的实例
这是脚本:
using UnityEngine;
public class Collide : MonoBehaviour
{
public Movement movement; // A reference to our PlayerMovement script
// This function runs when we hit another object.
// We get information about the collision and call it "collisionInfo".
void OnCollisionEnter(Collision collisionInfo)
{
// We check if the object we collided with has a tag called "Obstacle".
if (collisionInfo.collider.tag == "Obstacle")
{
movement.enabled = false; // Disable the players movement.
Debug.Log("Coollision occured");
}
}
}
正如我在第二张图片中看到的,您没有将运动参考添加到运动场。同时在脚本中您也没有分配引用。尝试在编辑器中分配,或者您可以创建对象。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句