Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 spanjoar · Feb 06, 2012 at 05:23 PM · animationdoor

Need help with my animation script

I'm trying to make a simple script to open and close a door. I'm a noob when it comes to scripting but this is what I have made so far:

 function OnMouseDown () {
 animation.Play("open");
 if (OnMouseDown) {
 animation.Play("close");
 }

}

But the script does understand that I want to make two different commands. This is what I want to achieve.

When I click on the door the door will open, and STAY open! When I click on it again the door will close and stay that way until I click on it again.

All help is appreciated.

Thanks.

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

Answer by DaveA · Feb 06, 2012 at 08:42 PM

if (OnMouseDown) doesn't make any sense.

You should set a boolean and test it:

 var isOpen = false;
 
 function OnMouseDown () {
  if (isOpen)
    animation.Play("close");
  else
    animation.Play("open");
 }
Comment
Add comment · Show 4 · 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 spanjoar · Feb 06, 2012 at 11:45 PM 0
Share

Thank you for your reply.

When I use the script with isOpen set to "false" the door repeat the "open" animation every time i click on it, and if I set isOpen to "true" it will repeat the "close" animation every time i click on the door. Can I turn isOpen to "true" when I click the door? If I'm not mistaken your script is automatically trying to decide if the door is open or closed, can I somehow command the door to change status to false/true when I click on it? Like this:

When I click on the door the animation plays and change to isOpen to "true". When I click again the "close" animation plays and change isOpen to "false".

avatar image FLASHDENMARK · Feb 07, 2012 at 01:04 PM 0
Share

Yes, you should every time you open/close the door change the isOpen boolean to the opposite of what it currently is.

avatar image spanjoar · Feb 07, 2012 at 06:40 PM 0
Share

I'm trying to, don't really know how though.

avatar image spanjoar · Feb 08, 2012 at 10:55 AM 0
Share

This is the solution:

var isOpen = false;

function On$$anonymous$$ouseDown () { if (isOpen) animation.Play("close"); else animation.Play("open"); isOpen = !isOpen; }

avatar image
0

Answer by tonydemot · Feb 08, 2012 at 05:23 AM

you could use ray casting and colliders

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

7 People are following this question.

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

Related Questions

Respawn script and door animation help 0 Answers

Trigger door animation with external trigger 1 Answer

Animation clip does not exist? 1 Answer

Door Movement Animation 3 Answers

Animate Doors and Button Through Script 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