在做相机视野跟随的时候, 在运行游戏的时候,出现了异常,并且相机不跟随角色移动了。
异常信息
NullReferenceException: Object reference not set to an instance of an object
FollowTarget.Start () (at Assets/Scripts/FollowTarget.cs:13)
NullReferenceException: Object reference not set to an instance of an object
FollowTarget.Update () (at Assets/Scripts/FollowTarget.cs:18)
出问题的代码
private Transform hero;
void Start () {
offset = transform.position - hero.position;// 13行
}
// Update is called once per frame
void Update () {
transform.position = offset + hero.position;// 18行
}
unity 2017 ngui 3.6.8