- Home /
transform.collider.isTrigger problem
I want to do something like if it hits a wall the trigger would be false,if it is an enemy, it is true. I am having a problem with this because when my enemy hits the wall, the trigger will be false forever in the game.. how can I make it as it is only false if it hits the wall and only true if it hits my character .
Answer by lvictorino · Feb 28, 2012 at 01:18 AM
I guess you want to have a look at the OnTriggerEnter method on your camera collider. Then check the object parameter to check if it's an enemy, then you can do what you want to do.
Answer by Echoshard · Feb 28, 2012 at 01:18 AM
You need to Set up Tags and Setup OnTrigger Enters and Exits.
Something Like this I think.
function OnTriggerEnter(col:Collider){
if(col.tag == "Player"){
collider.isTrigger = false;
}
if(col.tag == "Enemy"){
collider.isTrigger = true;
}
}
function OnTriggerExit(col:Collider)
{
if(col.tag == "Player"){
collider.isTrigger = true;
}
if(col.tag == "Enemy"){
collider.isTrigger = true;
}
}
Answer by Berenger · Feb 27, 2012 at 06:05 PM
Implement bot OnCollisionEnter and OnTriggerEnter. Do the tag check on both, and toggle isTrigger. I'm not sure what you're trying to achieve, but you could probably do it properly with physic layers.
Please next time, try being more clear in your problem description.
Your answer
Follow this Question
Related Questions
How to get sound to play on barrel Explosion 1 Answer
Can collision be detected when object IsTrigger? 1 Answer
How to make work a collision when is invisible? 3 Answers
2D game object trigger 1 Answer
Trigger collision detection problem 0 Answers