- Home /
onTriggerEnter accesing gameObject components
I am trying to disable a script and change its colour of enemies that are entering the trigger, but I can not seem to find a way to do this.
Here is the code of what I have tried so far:
function OnTriggerEnter (collide:Collider){
if(collide.gameObject.name == "enemy1R2" && doOnce == true){
Debug.Log(collide);
collide.gameObject.renderer.material.color = Color.yellow;
collide.gameObject.GetComponent("AI_nm1").enabled = false;
doOnce = false;
}
}
Answer by bodec · Apr 18, 2012 at 02:07 PM
are you getting your collision? From what im seeing you never asign collide to the enemy below the function and above the if place this line
enemy1R2 = GameObject.GetComponentswithTag("enemy1R2")
if you have more than one enemy with that tag you will needto make it a array.
I need to interact only with the enemy that collides with the trigger, wouldn't that method either effect all enemies with that tag or if working with an array you would be unable to check its that specific one thast colliding?
it will build a array with all tags but only effect the ones that collide
Your answer
Follow this Question
Related Questions
How do I make all game objects with a certain tag appear on trigger enter? (C#) 2 Answers
OnTriggerEnter Influencing all GameObjects of the Same Type 2 Answers
How to make a GameObject that collides but the player can go through it? 2 Answers
OnTriggerEnter Help? 2 Answers
Why won't the coin destroy when hit? 0 Answers