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 /
This question was closed May 01, 2013 at 09:06 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by AfricanMoney · May 01, 2013 at 07:31 AM · javascriptanimationsdoor

Door opening and closing script not working

I have this script attached to my door:

 var InRange : boolean = false;
 var PressA : boolean = false;
 var ThePlayer : Transform;
 
 var DoorClosed : boolean = true;
 var DoorOpen : boolean = false;
 
 function Start () 
 {
 
 }
 
 function Update () 
 {
     var distance : float = Vector3.Distance (ThePlayer.transform.position, transform.position);
     
     if (distance < 1.5f)
     {
         InRange = true;
         PressA = true;
     }
     else
     {
         InRange = false;
         PressA = false;
     }
 }
 
 function OnGUI ()
 {
     if (InRange == true && PressA == true)
     {
         GUI.Box (new Rect (460, 495, 40, 25), "Open");
         
         if(InRange == true && Input.GetButtonDown ("Fire1") && DoorClosed == true)
         {
             animation.Play ("OpenDoor");
             DoorOpen = true;
             DoorClosed = false;
         }
         
         else if (InRange == true && Input.GetButtonDown ("Fire1") && DoorOpen == true)
         {
             animation.Play ("CloseDoor");
             DoorClosed = true;
             DoorOpen = false;
         }
     }
 }

I have applied the two animations to the door and I have placed the player is the variable "ThePlayer", but when I go to open it the door jumps open without the animation and then plays the closing door animation. What am I doing wrong?

P.S Im using JavaScript

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by MrSteve1 · May 01, 2013 at 08:22 AM

this

  if(InRange == true && Input.GetButtonDown ("Fire1") && DoorClosed == true)
        {
          animation.Play ("OpenDoor");
          DoorOpen = true;
          DoorClosed = false;
        }
  
        else if (InRange == true && Input.GetButtonDown ("Fire1") && DoorOpen == true)
        {
          animation.Play ("CloseDoor");
          DoorClosed = true;
          DoorOpen = false;
        }


needs to be Update() not OnGUI()

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 AfricanMoney · May 01, 2013 at 08:45 AM 0
Share

Thanks mate it works again. What a stupid mistake on my behave :)

avatar image MrSteve1 · May 02, 2013 at 02:33 PM 0
Share

No worries, we all make them from time to time.

Follow this Question

Answers Answers and Comments

13 People are following this question.

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

Related Questions

Open doors with key & sound 1 Answer

Door to Next Level HELP! 2 Answers

Animation not playing with animation.Play 1 Answer

Sound effect on right click 1 Answer

How to open doors on a hinge like a real door? 3 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