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 munaeem · Sep 09, 2012 at 06:21 PM · doorkeyopenunlockcollect

How to open a gate with a key ?

Hi every one.

I am having problems with assigning key and stuff. So the question is that how do i assign a key to be collected then approach the door and the door opens automatically. Well i already have a script (not animation, because i am having problems with animation) so how do i add the key and unlocking script. Here is my java script to open the gate.

 #pragma strict
 var AngleX:float = 0.0;
 var AngleY:float = 90.0;
 var AngleZ:float = 0.0;
 
 private var targetValue : float = 0.0;
 private var currentValue : float = 0.0;
 private var easing : float = 0.05;
 
 var Target : GameObject;
 
 function Update(){
 
     currentValue = currentValue + (targetValue - currentValue) *easing; 
     Target.transform.rotation = Quaternion.identity;
     
     Target.transform.Rotate(0, currentValue,0);
 
 }
 
 function OnTriggerEnter (other : Collider){
 
     targetValue = AngleY;
     currentValue = 0;
 
 }
 
 function OnTriggerExit (other : Collider){
 
     currentValue = AngleY;
     targetValue = 0.0;
 
 }


OK, this script work with a triggered collider, which means that if you approach a collider which is triggered; the door will open very simple. What i want is that a script with a key so that when i walk to the key it collect my key and the key disappear. (Sorry i am doing to much of 'key' 'key'). My person is 3rd person

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 capcom · Sep 09, 2012 at 07:17 PM

Why not store whether the key has been picked up or not by the player in the player's script. So create a boolean variable like `hasKey` and set it to true if the key is picked up. The door script can access the `hasKey` variable from the player, and if the value is true, then the door opens.

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 munaeem · Sep 09, 2012 at 07:28 PM 0
Share

i don't get it please provide with codes. And what about the key script ?

avatar image capcom · Sep 09, 2012 at 09:11 PM 0
Share

I don't have time for the code (sorry), but I'll be more specific. Consider three things: your player, the key, and the door. The player has a script called playerScript attached, the door has a script called doorScript.

When the player picks up the key, a boolean variable inside playerScript called `has$$anonymous$$ey` is set to true (keep it to false as default). Now, when the player approaches the door, the doorScript is told to check the `has$$anonymous$$ey` variable in the playerScript to check if it is set to true. If it is true, then open the door. If it is false, then do nothing.

Hope that helps!

BTW, you shouldn't need a script for the key.

If I helped, please select it as the best answer. Thanks.

avatar image munaeem · Sep 09, 2012 at 10:12 PM 0
Share

ok thank you soo much for giving me time ill try it and reply back :) it will work probably :).

avatar image capcom · Sep 09, 2012 at 10:18 PM 0
Share

$$anonymous$$y pleasure. If you still need help, let me know.

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

9 People are following this question.

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

Related Questions

Help with making his work with a key 1 Answer

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

Open door with key 2 Answers

Activate object with key 1 Answer

[C#] Collect Key Fragments to unlock door, and Save Progress. 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