unity里面一个记分程序,运行的时候显示错误object reference not set to an object

《gamecontroller》程序usingUnityEngine;usingSystem.Collections;publicclassGameController:... 《game controller》程序using UnityEngine;using System.Collections;public class GameController : MonoBehaviour { public Vector3 SpawnValues; public GameObject[] diji; public int Number = 10; public float startwait = 2f; public float waveswait = 4f; public float eachwait = 1f; public GUIText Scoretext; private int score; void Start () { Debug.Log("spaceshooterstart....."); StartCoroutine(SpawnWaves()); Scoretext.text = "Score: " + score; } // Update is called once per frame void Update () { } IEnumerator SpawnWaves() { yield return new WaitForSeconds(startwait); while (true) { for (int i = 0; i < Number; i++) { Spawn(); yield return new WaitForSeconds(eachwait); } yield return new WaitForSeconds(waveswait); } } void Spawn() { GameObject o = diji[Random.Range(0, diji.Length)]; Vector3 p = new Vector3(Random.Range(-SpawnValues.x, SpawnValues.x), SpawnValues.y, SpawnValues.z); Quaternion q = Quaternion.identity; Instantiate(o, p, q); } public void AddScore(int v) { score += v; Scoretext.text = "Score: " + score; }}《DestoryByContact》程序using UnityEngine;using System.Collections;public class DestroyByContact : MonoBehaviour { public GameObject bombenemy; public GameObject bombplayer; private GameController gameController; public int score = 10; void start() { GameObject gameControllerObject = GameObject.FindWithTag("GameController"); if (gameControllerObject != null) { gameController = gameControllerObject.GetComponent(); } if (gameController== null) { Debug.Log("Could not find gamecontroller"); } } void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Boundary") { return; } if (other.gameObject.tag == "Player") { Instantiate(bombplayer,this.transform.position,this.transform.rotation); } Destroy(other.gameObject); gameController.AddScore(score);// 提示错误在这里 Destroy(this.gameObject); Instantiate(bombenemy, this.transform.position, this.transform.rotation); }} 展开
 我来答
百度网友a355bf0
2015-07-23
知道答主
回答量:16
采纳率:0%
帮助的人:13.2万
展开全部
gameController 的赋值改成这样试试

gameController = gameControllerObject.GetComponent<GameController>();
更多追问追答
追问
还是不行,同样的错误
追答
gameController 是不是空引用啊 
Debug.Log("Could not find gamecontroller");这句打印了吗
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式