- Home /
enemy awareness with colliders?
I have made an enemy and he has a movement script. He will follow the player all the time but i only want him to follow when aware. i put a box collider in front of him as his "sight" but how do i access that collider to change the aware variable to true when it touches the player and false when it isn't touching anymore? i am using javascript Thanks!
Answer by greatestprez · Nov 26, 2012 at 03:06 AM
If your trigger (i'm assuming your collider is a trigger collider) is attached directly to your enemy simply add the two functions OnTriggerEnter(), and OnTriggerExit to your script. If its not directly attached to your enemy, you will have to make a script for the object that the trigger is on and then put the two functions in there. Example:
function OnTriggerEnter(col : Collider) {
//insert code for when something enters here
}
function OnTriggerExit(col : Collider) {
//insert code for when something exits here
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613084513im_/https://answers.unity.com/themes/thub/images/avi.jpg)