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 kconwaykyle · Oct 15, 2012 at 01:36 AM · audiotriggersounddoor

Door Opens When Not In Trigger And Sound Help

I made a door and scripted it so whenever I hit "e" it opens or closes, however whenever i hit "e" it opens or closes regardless of where i am in the map. only when i step in the trigger at least once does it make it so i cant.

This is the script for the door; // Smothly open a door var smooth = 2.0; var DoorOpenAngle = 90.0; var DoorCloseAngle = 0.0; var open : boolean; var enter : boolean;

 //Main function
 function Update (){
 
 if(open == true){
 var target = Quaternion.Euler (0, DoorOpenAngle, 0);
 // Dampen towards the target rotation
 transform.localRotation = Quaternion.Slerp(transform.localRotation, target,
 Time.deltaTime * smooth);
 }
 
 if(open == false){
 var target1 = Quaternion.Euler (0, DoorCloseAngle, 0);
 // Dampen towards the target rotation
 transform.localRotation = Quaternion.Slerp(transform.localRotation, target1,
 Time.deltaTime * smooth);
 }
 
 if(enter == true){
 if(Input.GetKeyDown("e")){
 open = !open;
 }
 }
 }
 
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (enter) = true;
 }
 }
 
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
 
 if (other.gameObject.tag == "Player") {
 (enter) = false;
 }
 }
 //@youtube.com/user/maksimum654321

I am also wondering what to do to make a sound play whenever the door opens or closes as well.

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 sparkzbarca · Oct 15, 2012 at 02:01 AM

you have the bool enter.

It appears that determines whether your allowed to open the door right?

but when you declare a bool its default value is true;

so

 bool enter;
 
 if (enter)
 {
    will happen cause its true by default
 }

the answer is to go to where you declare true or the function OnStart() and set enter to false.

Comment
Add comment · Show 2 · 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 sparkzbarca · Oct 15, 2012 at 02:08 AM 0
Share

you want to look at audiosource class to add sound

if you have a game object and you'd like to play on open add a audiosource component to the object then call play

for example

GetComponent().Play();

since your newish just go into the editor select the door and

Component menu up top Audio Audio Source

now drag and drop in a sound to play. just find one on your comp to test with.

DISABLE play on awake, that will play the sound at the game start

now the code that actually opens the door just before it.

GetComponent().Play();

avatar image Seth-Bergman · Oct 15, 2012 at 03:11 AM 0
Share

pretty sure the default value for an uninitialized boolean is actually FALSE

but yeah, make sure it's not checked in the inspector

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

11 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

Related Questions

Sound on collision not working 1 Answer

Trigger door animation with external trigger 1 Answer

Why my sound it's not attaching to my Flashlight 2 Answers

Play Sound on trigger 2 Answers

Play sound on trigger, sound is coming from the trigger 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