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 10, 2013 at 09:02 PM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by Kan · May 10, 2013 at 07:37 PM · doorkeyopen

Door opening with a key, my scripts and problem

So I have my door open script which is working great:

 var Range : boolean = false;
 var ThePlayer : Transform;
 var sound : AudioClip;
 var sound2 : AudioClip;
 var DoorClosed : boolean = true;
 var text : GUIText; // it shows on screen "Press mouse button to open/close the door"
 function Start () 
 {
  text.enabled = false;
 }
 function Update () 
 {
     var distance : float = Vector3.Distance (ThePlayer.transform.position, transform.position);
     if (distance < 3f)
     {
        Range = true;
     }
     else
     {
        Range = false;
     }
     if (Range == true)
     {
        text.enabled = true;
        if(Range == true && Input.GetMouseButtonDown(0) && DoorClosed == true)
        {
          animation.Play ("dooropen");
          DoorClosed = false;
          audio.PlayOneShot(sound);
        }
        else if (Range == true && Input.GetMouseButtonDown(0) && DoorClosed == false)
        {
          animation.Play ("doorclose");
          DoorClosed = true;
          audio.PlayOneShot(sound2);
        }
     }
     else if (Range == false)
     {
     text.enabled = false;
     }
 }

And my key script which works too:

 var Range : boolean = false;
 var ThePlayer : Transform;
 var text2 : GUIText;
 var GotKey : boolean = false;
 function Start () 
 {
  text2.enabled = false;
 }
 function Update () 
 {
     var distance : float = Vector3.Distance (ThePlayer.transform.position, transform.position);
     if (distance < 3f)
     {
        Range = true;
     }
     else
     {
        Range = false;
     }
     if(Range == true)
     {
        text2.enabled = true;
     }
        if(Range == true && Input.GetMouseButtonDown(0))
        {
        animation.Play ("key");
        GotKey = true;
        }
     else if(Range == false)
     {
        text2.enabled = false;
     }
 }

And my question is.. how to add needed key to a door script.

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 roojerry · May 10, 2013 at 07:46 PM

You already have the GotKey boolean in you Key script. I would give the door a reference to the key object needed to open the door and just use the GotKey boolen in the door opening logic.

something like:

 if(Range == true && Input.GetMouseButtonDown(0) && DoorClosed == true && key.GotKey)
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

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

Scripting issue with opening a door with a key. 2 Answers

How to make 2 doors with 2 diffrent keys 2 Answers

Make doors open with different keys? 1 Answer

Pick up key and unlock a locked door 1 Answer

Why is my door opening and closing at the same time????????? 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