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); }}
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询