Unity - A计划(一年有效期) 扫二维码继续学习 二维码时效为半小时

(61评价)
价格: 2208.00元
在Stealth秘密行动中主角进入摄像机和激光射线门不触发警报
塔里木河丶发起了问答2019-03-20
2
回复
297
浏览

在进入激光门的时候不会触发警报,主角和激光门已经设置了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();

    }


}

 

所有回复
发表回复
你还没有登录,请先 登录或 注册!