在进入激光门的时候不会触发警报,主角和激光门已经设置了collider
报错内容如下:
NullReferenceException: Object reference not set to an instance of an object
Laser.OnTriggerStay (UnityEngine.Collider other) (at Assets/Scripts/Laser.cs:58)
报错代码:
void OnTriggerStay(Collider other)
{
if (other.tag == "Player")
{
GameController._intance.SeePlayer(other.transform);
}
下面是GameController的代码:
public class GameController : MonoBehaviour
{
public static GameController _intance;
public bool alermON = false;
public Vector3 lastPlayerPostion = Vector3.zero;
public AudioSource audio1;
void Awake()
{
alermON = false;
}
void Update()
{
AlermLight._intance.alermON = this.alermON;
if (alermON)
{
PlaySiren();
}
else
{
StopSiren();
}
}
public void SeePlayer(Transform player)
{
alermON = true;
lastPlayerPostion = player.position;
}
private void PlaySiren()
{
if (!audio1.isPlaying)
{
audio1.Play();
}
}
private void StopSiren()
{
audio1.Stop();
}
}