using UnityEngine;
using System.Collections;
public class Destorybycontact : MonoBehaviour {
public GameObject explosion;
public GameObject playerexplosion;
public int score1;
private Gamecontrol game;
void start()
{
GameObject gamecontrolobject = GameObject.FindWithTag("GameController");
if (gamecontrolobject != null)
{
game = gamecontrolobject.GetComponent<Gamecontrol>();
}
if(gamecontrolobject == null)
{
Debug.Log("can't find 'Gamecontrol' scipt");
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "boundary")
{ return; }
Instantiate(explosion, transform.position, transform.rotation);
if (other.tag == "Player")
{
Instantiate(playerexplosion, other.transform.position, other.transform.rotation);
}
game.addScore(score1);
Destroy(other.gameObject);
Destroy(gameObject);
}
}
报错NullReferenceException: Object reference not set to an instance of an object。显示这个是空值game.addScore(score1);。也不知道为什恶魔,求解