Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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 t0n1s · May 23, 2013 at 12:28 AM · buttondoor

Door - Press button to open

Hi everyone. I'm trying to make a game but im stuck in the door opening. I want to like hit the button e and the door open then if i want hit e again and close it. Can someone tell me all the steps to do it ?

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

Answer by Kiloblargh · May 23, 2013 at 12:51 AM

You should have a game controller script, and a script that goes on the player, and a script that goes on the door.

In the game controller script, make a reference to the door script to be assigned later:

 var thisDoor : DoorScript;

then a script on your player object that has a reference to the game controller script:

 var gameController : ControlScript;

The player object needs a collider attached, and the door needs to be tagged "Door" and have a trigger collider in front of it.

The player object's script should have an OnTriggerEnter which tells the game controller what door you are standing in front of.

 function OnTriggerEnter (other : collider)
 {
 if (other.gameObject.tag == "Door")
     {
     gameController.thisDoor = other.gameObject.GetComponent (DoorScript);
     }
 }

DoorScript needs a variable to tell the door's current state:

 var isOpen : System.Boolean = false;

Then back in your control script, you need this in Update:

 function Update()
 {
 if (Input.GetKeyDown("e"))
     {
     if (thisDoor.isOpen)
         {
         thisDoor.Close();
         }
     else 
         {
         thisDoor.Open();
         }
     } 
 }

What the DoorScript functions "Open()" and "Close()" will do is left to you. For starters, try just setting the door object inactive or active and once that works, then get it to animate.

If none of the above made sense to you, read the manual some more.

Comment
Add comment · Show 3 · 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 t0n1s · May 30, 2013 at 04:08 PM 0
Share

Sorry for the delay. I can't make the door move normaly all it does is rotates on the spot it's on. I saw a tutorial on youtube for how to make an openable door and he created a gameobject and placed in where te door rotates. I did the same but nothing happens. Any help on that ?

avatar image Kiloblargh · May 30, 2013 at 11:39 PM 0
Share

You have to make sure to update the script references to the hinge object's transform ins$$anonymous$$d of the original door object's transform, which should be a child of the hinge object.

avatar image t0n1s · Jun 01, 2013 at 08:28 AM 0
Share

I added a box collider on the door and moved it a bit left where the door leans, The movement is preety good but when i animate it, it goes crazy.

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

14 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

Related Questions

Simple Script - and no result 2 Answers

Change button icon for each without multiple GUISkins 1 Answer

help with door script! 3 Answers

GUI Button not working...but the the script is correct... 2 Answers

Making multitouch button 0 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