0

我正在制作一个移动相机的脚本,但出现此错误:NullReferenceException: Object reference not set to an instance of an object

但是我的脚本有效,控制台上没有崩溃或只是这个错误,你知道为什么吗?有代码:

  public Transform target;
  public Transform[] views;
  public Camera cam;

  public float lerpSpeed;
  Transform currentView;


    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Alpha1)){
            currentView = views[0];
        }
        if (Input.GetKeyDown(KeyCode.Alpha2)){
            currentView = views[2];
        }
        if (Input.GetKeyDown(KeyCode.Alpha3)){
            currentView = views[1];
        }
        if (Input.GetKeyDown(KeyCode.Alpha4)){
           currentView = views[3];
        }


    }

    void LateUpdate() {
        cam.transform.position = Vector3.Lerp(cam.transform.position,currentView.position, lerpSpeed * Time.deltaTime);
        cam.transform.LookAt(target);
    }
4

0 回答 0