NullReferenceException:未将对象引用设置为对象的实例 SceneControllerEngine.Update()(在Assets / 02_EngineAR / Scripts / SceneControllerEngine.cs:60)
using UnityEngine;
using System.Collections;
public class SceneControllerEngine : MonoBehaviour {
//We use this to store all tagged objects in the Scene to be included in the fading effect
public GameObject[] engineArray;
//Store a Gameobject reference to the dolphin to disable/enable clicking/touching behaviour
public GameObject engineClick;
//The rest of these are public references to objects we are going to switch on and off rather than fade
public GameObject front;
public GameObject back;
public GameObject middle;
public GameObject lights;
public AudioSource engineStartFX;
//Reference to the Fadescript behaviour
FadeScript fadingScript;
// Use this for initialization
void Start () {
//Load all tagged objects into an array
this.engineArray = GameObject.FindGameObjectsWithTag ("EngineScene");
}
// Update is called once per frame
void Update () {
//FadeOut function
//Currently uses Keyboard input, change to whatever
if (Input.GetKey (KeyCode.S)) {
Debug.Log ("FadeOut Pressed");
//Switch on objects to be switched
front.SetActive(false);
back.SetActive(false);
middle.SetActive(false);
lights.SetActive(false);
engineStartFX.Pause();
//Disable collider for clicking/touching events
engineClick.collider.enabled = false;
//For each loop to take every instance of the FadeScript on each tagged object and trigger the fadeOut boolean
foreach (GameObject engineScene in engineArray) {
fadingScript = engineScene.GetComponent<FadeScript> ();
fadingScript.fadeOut = true;
}
}
}
}
一直在努力解决这个问题,导致更多问题第60行:fadingScript.fadeOut = true;不断抛出错误。我花了很长时间才想到我在圈子里走来走去..