Hey, so, I'm currently doing a project for a class, and I'm having so much trouble going about it. What I'm trying to do is activating an animation of closing a door (slide from left to the right wall) and flashing lights when my first person controller triggers it by stepping on a game object that I've placed before the door.
Currently, I'm trying to use the function OnTriggerEnter, but I have no clue how to script that when my FP-controller steps onto the game object stationed before the door, it will cause the door to shut and the lights above to start flashing. Oppositely, I want to use the OnTriggerExit, so when my controller leaves the game object, the door opens and the lights stop flashing.
Can anyone help? I've asked a couple of friends, but all they did was just confuse me even more. Thank you for any future responses!
The answers on this question are probably just confusing you more , so I shall start from the beginning to help explain the process you need to follow.
I'll be using video links to help you see the concepts working.
Using Triggers and OnTriggerEnter :
Note how setting the trigger to True (tick), and setting the Mesh Renderer to False (Untick), you can create a 'zone' that you can place where you want the trigger to occur.
Using Find and SendMessage :
The 'react' script for example would activate the animation (instead of changing the material) Then the other important part is the Find and SendMessage commands.
Unity animation intro :
Overview on animation.
If you watch these and are still having trouble, I am happy to help you edit your scripts to get the effect you are after.
Scroll down to Section 2: Code Development
Download and watch : 5 - ButtonPush , and , 6 - Temple Door .
answered Apr 15 '12 at 04:58 AM
Well the door would be just a matter of creating an animation but the lights im not too sure on doing, are they just Directional Lights?
answered Apr 14 '12 at 07:12 PM
Where are you stuck? Start simple. Attach a script with ontriggerenter and ontriggerexit to your trigger gameobject, and get it to Debug.Log when these are called.
After this, in your trigger script, add references to your door gameobject and light gameobject. Set them to active true/false when the controller enters/exits.
Then build upon that :)
Did that help? Though I could write it all for you, you won't learn anything ;)
answered Apr 14 '12 at 07:24 PM