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 Ouija · Feb 05, 2014 at 01:08 AM · doorkeypress

Mod-ing a Unity Door Key Switch

Hello guys, I was playing around with the "DoneDoorAnimation" that came with the Unity's Stealh project. Its the script that makes the door open when you have a key. I'm guessing it's finel to post this script here seems it's unity that wrote it? I am only looking to change ONE thing. I don't want the door to open automatically, I want it to open when you press the key. "F". Anyone feel like helping? here is the original script.

// I tried to adding something like this But it gave me an error on the VoidTriggerExit//

 if(Input.GetButton("Switch"))

///

 using UnityEngine;
 using System.Collections;
 
 public class DoneDoorAnimation : MonoBehaviour
 {
     public bool requireKey;                            // Whether or not a key is required.
     public AudioClip doorSwishClip;                    // Clip to play when the doors open or close.
     public AudioClip accessDeniedClip;                // Clip to play when the player doesn't have the key for the door.
     
     
     private Animator anim;                            // Reference to the animator component.
     private DoneHashIDs hash;                        // Reference to the HashIDs script.
     private GameObject player;                        // Reference to the player GameObject.
     private DonePlayerInventory playerInventory;    // Reference to the PlayerInventory script.
     private int count;                                // The number of colliders present that should open the doors.
     
     
     void Awake ()
     {
         // Setting up the references.
         anim = GetComponent<Animator>();
         hash = GameObject.FindGameObjectWithTag(DoneTags.gameController).GetComponent<DoneHashIDs>();
         player = GameObject.FindGameObjectWithTag(DoneTags.player);
         playerInventory = player.GetComponent<DonePlayerInventory>();
     }
     
     
     void OnTriggerEnter (Collider other)
     {
         // If the triggering gameobject is the player...
         if(other.gameObject == player)
         {
         
             
             // ... if this door requires a key...
             if(requireKey)
             {
 
 
                 // ... if the player has the key...
                 if(playerInventory.hasKey)
                     // ... increase the count of triggering objects.
                     count++;
                 else
                 {
                     // If the player doesn't have the key play the access denied audio clip.
                     audio.clip = accessDeniedClip;
                     audio.Play();
                 }
             }
             else
                 // If the door doesn't require a key, increase the count of triggering objects.
                 count++;
         }
         // If the triggering gameobject is an enemy...
         else if(other.gameObject.tag == DoneTags.enemy)
         {
             // ... if the triggering collider is a capsule collider...
             if(other is CapsuleCollider)
                 // ... increase the count of triggering objects.
                 count++;
         }
     }
     
     
     void OnTriggerExit (Collider other)
     {
         // If the leaving gameobject is the player or an enemy and the collider is a capsule collider...
         if(other.gameObject == player || (other.gameObject.tag == DoneTags.enemy && other is CapsuleCollider))
             // decrease the count of triggering objects.
             count = Mathf.Max(0, count-1);
     }
     
     
     void Update ()
     {
         // Set the open parameter.
         anim.SetBool(hash.openBool,count > 0);
         
         // If the door is opening or closing...
         if(anim.IsInTransition(0) && !audio.isPlaying)
         {
             // ... play the door swish audio clip.
             audio.clip = doorSwishClip;
             audio.Play();
         }
     }
 }
 
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 Ouija · Feb 05, 2014 at 01:56 AM

Figured it out myself if anyone is interested. But now I have the issue of getting the door to close once its open?

             // ... if this door requires a key...
             if(requireKey)
             {
 
                 
                 if(Input.GetButton("Switch"))
                 // ... if the player has the key...
                 if(playerInventory.hasKey)
                     // ... increase the count of triggering objects.
                     count++;
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.

Follow this Question

Answers Answers and Comments

18 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

Related Questions

A node in a childnode? 1 Answer

Maya to Unity Animation using Box Colliders 1 Answer

Door Open on keydown and Close Door on same keydown? 1 Answer

How can I make the keys randomly change after each keypress? 1 Answer

animate only when clicked 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