Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by RL4662 · Apr 14, 2012 at 06:25 PM · animationtriggerdoor

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by AlucardJay · Apr 15, 2012 at 04:58 AM

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

http://www.unity3dstudent.com/2010/07/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

http://www.unity3dstudent.com/2011/02/beginner-b28-sendmessage-to-call-external-functions/

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

http://www.unity3dstudent.com/2010/09/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 :

http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

http://unity3d.com/support/documentation/ScriptReference/GameObject.Find.html

http://unity3d.com/support/documentation/ScriptReference/GameObject.SendMessage.html

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

http://www.unity3dstudent.com/category/modules/beginner/

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.

http://www.3dbuzz.com/vbforum/content.php?225-Unity-3rd-Person-Platformer-Game

Scroll down to Section 2: Code Development

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yezzer · Apr 15, 2012 at 07:13 AM 0
Share

Do what this man says. $$anonymous$$uch more thorough info than I supplied.

avatar image RL4662 · Apr 26, 2012 at 06:44 PM 0
Share

Sorry it took me so long to reply! I did look through all this info, and it totally helped! I did it! Anyways... ahem Thank you so much! All of you!

avatar image
0

Answer by JayMHelpsU · Apr 14, 2012 at 07:12 PM

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?

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image JayMHelpsU · Apr 14, 2012 at 07:16 PM 0
Share

The code for the animation is gameObject.animation.Play("animation name here");

avatar image RL4662 · Apr 14, 2012 at 07:40 PM 0
Share

I actually chose to use point lights because I wanted to the lights to rotate as well (so they would spin in circles).

As for the animations, I had those already created, but I'm just not sure how I can trigger them via stepping on the game object with the function OnTriggerEnter and OnTriggerExit scripts.

avatar image JayMHelpsU · Apr 14, 2012 at 07:43 PM 0
Share

You can use a trigger on the floor and docking the code with OnTriggerEnter to that object on the floor :)

avatar image RL4662 · Apr 14, 2012 at 07:50 PM 0
Share

Could you elaborate xD? Would the game object be that trigger?

avatar image JayMHelpsU · Apr 14, 2012 at 08:37 PM 0
Share

Ok, say you made an invisible object on the ground as a trigger, so when the player walks on it, it activates OnTriggerEnter. In order for that to activate you need to make a code and dock the code to that object on the floor. I hope this helped in the trigger part :/

avatar image
0

Answer by yezzer · Apr 14, 2012 at 07:24 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 ;)

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yezzer · Apr 14, 2012 at 07:26 PM 0
Share

Also look at iTween for animating the door and light :) you could get some nice, simple effects with that.

avatar image JayMHelpsU · Apr 14, 2012 at 07:29 PM 0
Share

Ahhh yet again yezzer brilliant idea, why didnt i think of iTween i use it all the time DAHH :)

avatar image RL4662 · Apr 14, 2012 at 07:48 PM 0
Share

Thank you for that explanation yezzer! What I have right now is this:

// Destroy everything that enters the trigger

function OnTriggerEnter (Player : Collider) { if(Player.gameObject == "Prisoner") gameObject.Send$$anonymous$$essage }

As you can see, this script is still very unfinished xD! So, I think I have the OnTriggerEnter function correct, but when I start writing within the brackets, that is where I'm stuck. When I was at school and talked to my friend, he said something about using a send message script. I looked it up on the Unity Script reference, but it ended up confusing me even more (Sorry for my very little understanding about all of this. This is my first year scripting)!

You've helped a lot already, but could you briefly explain the true/false part? I remember hearing our $$anonymous$$cher talking about it, but it's still an area where I'm still unsure about.

avatar image yezzer · Apr 14, 2012 at 08:02 PM 0
Share

function OnTriggerEnter (Player : Collider) { if(Player.gameObject == "Prisoner"){ Debug.Log("prisoner entered trigger"); } } Attach that script to the trigger object, open the console, press play, move the gameobject with the name Prisoner into the trigger. Check the console for that message. Is that working?

avatar image yezzer · Apr 14, 2012 at 08:03 PM 0
Share

Note: on iPad. Bad formatting etc.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

play a door animation with collider 1 Answer

Trigger door animation with external trigger 1 Answer

Created an Open Close Animation, but script wont activate both doors? 1 Answer

How do you tigger an animation with a box collider in Unity 4? 0 Answers

Play 2D animations via trigger parameters 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges