- Home /
On trigger exit not working
I am having trouble with on trigger exit function. When I enter the trigger it works properly, but even if im still in the trigger the OnTriggerExit Function will activate. Please help.
Code:
var trigger : int = 1;
var detection : int = 1;
var Timer : int = 2000;
function Start () {
}
function OnTriggerEnter (other : Collider) {
detection = 3;
}
function OnTriggerExit (other : Collider) {
detection = 2;
if(detection == 2)
{
yield WaitForSeconds (5);
Debug.Log("Ware is he?");
}
}
function Update () {
if(detection == 3)
{
if(trigger == 1)
{
Debug.Log("Get Him!");
trigger = 0;
}
}
}
Answer by Lugia · Jul 18, 2014 at 09:03 AM
Although not sure... Try this method...
2 object you want to test trigger Both give rigidbody and collider
Then, choose 1 object (the object you want to run the trigger script) and click collider isTrigger, another object no need.
Try run it and test, hope it helps.
Answer by himanshugupta159 · Jul 07, 2019 at 05:46 AM
Hey,have written a blog regarding "How to make your colliders work as triggers" and to cool stuff with it in Unity.
These blogs targets Developers who are just starting with unity.So help me to reach out to them. link text I hope it will be HelpFull.