this is my code:
using UnityEngine;
using System.Collections;
public class PlayerDecection : MonoBehaviour {
public AnimalAI AIMotor;
public AudioClip SFX;
void OnTriggerEnter (Collider col)
{
if(col.tag == "Player")
{
AIMotor.Player = col.gameObject;
AIMotor.PlayerOnSight = true;
GetComponent().PlayOneShot(SFX);
}
}
void OnTriggerExit (Collider col)
{
if(col.tag == "Player")
{
AIMotor.Player = null;
AIMotor.PlayerOnSight = false;
GetComponent().Stop();
}
}
}
↧