- Home /
Boolean wont acitvate if the enemy enters a trigger
Hello I have a Script this script is very simple i have a enemy and i have a boxcollider called waypoint. When the AI (enemy) enters the trigger a boolean should be true. But its not happening. the AI has the tag Enemy on it. So.... here is my script
#pragma strict
var enter : boolean = false;
var Enemy : GameObject;
function OnTriggerEnter (poppen : Collider) {
if(poppen.collider.tag == Enemy.tag)
enter = true;
}
Does the AI have a collider attached? If so, is the variable Enemy initialised
@pauloapsantos96 yes it have a boxcollider on it and the tag is a standard tag
I don't know Unityscript that well anymore but it looks correct, but colliders aren't the only thing you need.
Add a Rigidbody to him and put is$$anonymous$$inematic = true
This may help also with formatting as I can't tell to well with Unityscript but in C# the way you detect tags is this (could be the same in US)
if(poppen.gameObject.tag == "NameOfTag");
So anything with the tag of NameOfTag will react with it.
@N1warhead Tank you so much i am thinking of this the whole day :)
Answer by jtsmith1287 · Oct 16, 2014 at 05:07 PM
When using any kind of collider, be it a mesh collider, box collider, capsule, etc, one of the colliding objects must also have a RigidBody component. If you need collision but don't want physics, simply check the IsKinematic box. I'm just making an assumption here, so hopefully this is the problem.
Your code looks fine, and you don't need to hardcode "NameOfTag". That is bad. If Enemy.tag is "NameOfTag", then if(poppen.collider.tag == Enemy.tag)
will return True if poppen.collider.tag is also "NameOfTag". So, make sure the tags are set, and that the gameobjects have rigid body components. Good luck!
I have already the answer in the comments but you are the only one who give the answer
Oh I didn't actually see that they also mentioned the rigid body issue in the comment. I just skimmed and saw the tag hardcoding. :P
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Gesture Sequences in javascript 1 Answer
Collider not working... 0 Answers
OnTriggerEnter Does Not Recognize Collider That Is Moved By iTween 0 Answers
Need help with game points and trigger 2 Answers