- Home /
create event on collision
hi. How do I do so that when the character collides with and object(an invisible object that the player can walk through) an event comes. like an object will be created or something will be moved.
for instance. the Character moves in a hallway and walks into this trigger object(walks through it) and then a door will be closed.(the door is just an example)
Answer by Sokco816 · Jun 13, 2012 at 10:28 PM
Tag your character as "Player" and then add this script to your trigger object(s):
function OnTriggerEnter(other : Collision){
if(other.gameObject.tag=="Player")
DoSomething();
}
function DoSomething(){
//code that will close door
}
Good luck with the project!
Answer by asafsitner · Jun 13, 2012 at 05:59 PM
`OnCollisionEnter` is what you need.
Likewise, there is `OnTriggerEnter`.
Your answer
Follow this Question
Related Questions
Collision not triggered by box collider 2 Answers
Plane flyby triggering/help 1 Answer
How do I trigger an event (health loss) only once? 3 Answers