Sliding door animation question.

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 :

  • Beginner B13 - Trigger Collision Detection

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 :

  • Beginner B28 - Send Message

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 :

  • Intermediate I02 – Basic Animation and Events

Overview on animation.

  • Also , and probably most Importantly , read the Unity Scripting Reference on the commands you want to use :

  • Here is the link to other video’s in the beginner set by Unity3Dstudent :

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.


For an example , you could also watch these video’s (this is just to show how someone else is using these concepts).
Remember this is just an example , not a tutorial for you to follow.
This is part of a much bigger project, and it is also in C# , not unity JavaScript.
So just focus on the gameObject , the Trigger function, and the GameObject.Find commands.

Scroll down to Section 2: Code Development

Download and watch : 5 - ButtonPush , and , 6 - Temple Door .

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?

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 :slight_smile:

Did that help? Though I could write it all for you, you won’t learn anything :wink: