• 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 revanl · Apr 16, 2014 at 11:26 PM · elevator

elevator with buttons

hello i am trying to script an elevator i want it to move to the second floor when i press the f button and to the third floor if i press the g button. I made a platform i made a first floor gameobject and a third and second floor gameobject but the problem with my script is that when i press the f button it goes to the second floor but when i add the g button scrip the f button bugs and to unbug it the g button has to be pressed so that the f button works i don't know what to do as i said i want it to go to the second floor when i press f and i want it to go to the third floor when i press g . this is my scrip

 var smooth = 2.0;
 var DestinationSpot:Transform;
 var OriginSpot:Transform;
 var up : boolean;
 var down : boolean;
 //Main function
 function Update ( ){
  if(transform.position == DestinationSpot.position)
     {
         Switch = true;
     }
     if(transform.position == OriginSpot.position)
     {
         Switch = false;
     }
 if(up == true){
 transform.position = Vector3.MoveTowards(transform.position, DestinationSpot.position, smooth);
 // Dampen towards the target rotation
 transform.position = Vector4.MoveTowards(transform.position, OriginSpot.position,
 Time.deltaTime * smooth);
 }
  
 if(up == false){
 transform.position = Vector3.MoveTowards(transform.position, OriginSpot.position, smooth);
 // Dampen towards the target rotation
 transform.position = Vector4.MoveTowards(transform.position, DestinationSpot.position,
 Time.deltaTime * smooth);
 }
  
 if(down == true){
 if(Input.GetKeyDown("f")){
 up = !up;
 }
 }
  
 }
  
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (down) = true;
 }
 }
  
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
  
 if (other.gameObject.tag == "Player") {
 (down) = false;
 }
 }
 this was the first scrip this is the second
 var smooth = 2.0;
 var ThirdSpot:Transform;
 var OriginsSpot:Transform;
 var left : boolean;
 var right : boolean;
 var //Main function
 function Update ( ){
  if(transform.position == ThirdSpot.position)
     {
         Switch = true;
     }
     if(transform.position == OriginsSpot.position)
     {
         Switch = false;
     }
 if(left == true){
 transform.position = Vector3.MoveTowards(transform.position, ThirdSpot.position, smooth);
 // Dampen towards the target rotation
 transform.position = Vector4.MoveTowards(transform.position, OriginsSpot.position,
 Time.deltaTime * smooth);
 }
  
 if(left == false){
 transform.position = Vector3.MoveTowards(transform.position, OriginsSpot.position, smooth);
 // Dampen towards the target rotation
 transform.position = Vector4.MoveTowards(transform.position, ThirdSpot.position,
 Time.deltaTime * smooth);
 }
  
 if(right == true){
 if(Input.GetKeyDown("g")){
 left = !left;
 }
 }
  
 }
  
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (right) = true;
 }
 }
  
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (right) = false;
 }
 }

i placed them in two different javascript files after that i placed them into the same cube which is the elevator

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

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

Answer by revanl · Apr 19, 2014 at 09:37 PM

never mind i got it to work

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

20 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Material doesn't have a color property '_Color' 4 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 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