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
1
Question by Rikanano · Dec 04, 2010 at 12:10 AM · animationdoor

Door Animation, Script Help Please!

I have a door animation, which has two elements in it as ive done it in 3Ds Max and one side opens to the left and the other opens to the right.

Can anyone be kind enough to show me some code that could work with this? Or at least point me in the right direction?

Animation Timing: 0-50 : Opening 51-60 : Open 61-100 : Closing

Also the animation is just named "Door" cheers in advance!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer Wiki

Answer by MC HALO · Dec 04, 2010 at 02:45 AM

Ok this script is done in JAVA i will give you two examples the first is if the player steps on something the door will open and the second is if the game runs the animation will play automatically :)

example 1:

function OnControllerColliderHit (hit : ControllerColliderHit){

if(hit.gameObject.tag == "Door") { // create a tag in unity and name it door and attach it to the door gameobject

animation.Play ("Door");

} }

the example above works if the player has a character controller around him, if the player hits the door it will then open up

example 2

This example is to make the door open automatically :

function Start () {

animation.Play("Door");

}

i just remembered another way this one is if you collide with something in the game world for example if you hit the bed the door will open

example 3:

function OnControllerColliderHit (hit : ControllerColliderHit){

if(hit.gameObject.tag == "bed") { // create a tag in unity and name it bed and attach it to the bed gameobject.

animation.Play ("Door");

// as soon as the player collides with the bed it will open the door :)

} }

now if the ideas worked for you let me know and if you are interested i can teach you a even better way of opening doors. i can show you how to use raycast to open doors this is a lot cooler because its like stuff you see in shopping centres when you walk next to a door it opens automatically and this is what raycast will do :))) hope these ideas helped :)

Comment
Add comment · Show 6 · 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 Rikanano · Dec 04, 2010 at 02:51 PM 0
Share

Hey, thanks thats a great help!

Yeah ive done a bit of research into RayCast and that idea would be great for my game! I will use example 3 for the time being as im being assessed on $$anonymous$$onday so i need some code to open my doors lol!

Thanks alot your a life saver (:

avatar image MC HALO · Dec 05, 2010 at 02:55 AM 1
Share

your most welcome i will make a tutorial on raycast and i will give you the link :)

avatar image Rikanano · Dec 05, 2010 at 04:13 AM 0
Share

Okay thank you so much! :D

avatar image MC HALO · Dec 05, 2010 at 04:24 AM 0
Share

:) your welcome

avatar image cory · Feb 28, 2011 at 02:00 AM 0
Share

Is there a chance you could show me the raycast tutorial because i'm trying to do the same as the previous guy only Im really new at setting up colliders, and knowing where to attach the script.

Show more comments
avatar image
0

Answer by BerggreenDK · Dec 04, 2010 at 12:59 AM

This is C#

GameObject.Find("DoorObject").animation.play("Door");

???

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Animation clip does not exist? 1 Answer

switch > door animation 0 Answers

Looking for tutorial for door animation using mecanim 2 Answers

Unity 4.0 Animation 1 Answer

FPSController Collision with moving objects 2 Answers


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