Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by kzelazny · Aug 30, 2016 at 06:06 PM · triggerobjectsoundlight

Lights shutting down with sound

Hi, Im beginner with Unity, and even more with scripting i mostly modify the scripts i found. What im trying to achieve is lights shuting down one after another, with sound effect connected to every shutdown of the light.

#pragma strict var light_down_0 : GameObject; var light_down_1 : GameObject; var light_down_2 : GameObject; var light_down_3 : GameObject; var light_down_4 : GameObject; var played = false; var trig = false; var clickSound: AudioClip; /////When player enters trigger/////// set to true/////// function OnTriggerEnter (other : Collider) { %|1512355362_1|% } //////Enable renderer and trigger sound and timer///// function Update () { %|971779091_2|% %|86938754_3|% %|-166982660_4|% %|-571540330_5|% } //// timer //// function removeovertime () { %|-1436862808_6|% %|100986914_7|% %|36113627_8|% %|1401870186_9|% %|-516028577_10|% %|-825324713_11|% %|1599428303_12|% %|-445450465_13|% %|1633754797_14|% %|-1105708243_15|% %|2036316252_16|% %|-913393898_17|% %|-2138975816_18|% %|-1390553392_19|% %|-1545792410_20|% %|1846181786_21|% } //// sound ///// function makehimscream_0 () { %|-1171808759_22|% %|-1183411412_23|% %|-2045067513_24|% %|-1710635996_25|% } function makehimscream_1 () { %|-451771264_26|% %|-1682377517_27|% %|7164834_28|% %|1675370969_29|% } function makehimscream_2 () { %|-1052795000_30|% played = true; %|2104514616_32|% %|1598251606_33|% } function makehimscream_3 () { %|384067722_34|% %|500527016_35|% %|323764729_36|% %|1087399600_37|% } function makehimscream_4 () { %|-539729754_38|% played = true; %|1249881886_40|% %|1928674998_41|% }

Light are shuting down correctly but I don't hear the sound with second shutdown of the lamp. Any ideas what im missing?
Comment
Add comment · Show 1
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 kzelazny · Aug 30, 2016 at 06:26 PM 0
Share
 #pragma strict
 var light_down_0 : GameObject;
 var light_down_1 : GameObject;
 var light_down_2 : GameObject;
 var light_down_3 : GameObject;
 var light_down_4 : GameObject;
 
 var played = false;
 var trig = false;
 
 var clickSound: AudioClip;
 
 
 /////When player enters trigger/////// set to true///////
 function OnTriggerEnter (other : Collider) {
     trig = true;
 }
 //////Enable renderer and trigger sound and timer/////
 function Update () {
     if (trig == true) {
         light_down_0.GetComponent.<Light>().enabled = false;
         removeovertime ();
 
 
 
     }
 }
 //// timer ////
 function removeovertime () {
     makehimscream_0 ();
     yield WaitForSeconds (3);
     light_down_0.gameObject.SetActive (false);
     makehimscream_1 ();
     yield WaitForSeconds (3);
     light_down_1.gameObject.SetActive (false);
     makehimscream_2 ();
     yield WaitForSeconds (3);
     light_down_2.gameObject.SetActive (false);
     makehimscream_3 ();
     yield WaitForSeconds (3);
     light_down_3.gameObject.SetActive (false);
     makehimscream_4 ();
     yield WaitForSeconds (3);
     light_down_4.gameObject.SetActive (false);
     
 }
 //// sound /////
 function makehimscream_0 () {
     if (!played) {
         played = true;
         light_down_0.GetComponent.<AudioSource>().PlayOneShot(clickSound);
     }
 }
 
 function makehimscream_1 () {
     if (!played) {
         played = true;
         light_down_1.GetComponent.<AudioSource>().PlayOneShot(clickSound);
     }
 }
 
 function makehimscream_2 () {
     if (!played) {
         played = true;
         light_down_2.GetComponent.<AudioSource>().PlayOneShot(clickSound);
     }
 }
 
 function makehimscream_3 () {
     if (!played) {
         played = true;
         light_down_3.GetComponent.<AudioSource>().PlayOneShot(clickSound);
     }
 }
 
 function makehimscream_4 () {
     if (!played) {
         played = true;
         light_down_4.GetComponent.<AudioSource>().PlayOneShot(clickSound);
     }
 }
 

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CapitalLlama · Aug 31, 2016 at 02:31 AM

You are assigning the global variable "played" to true on the first sound. Then the rest check if played. Since played = true still, they never play.

Glancing at your code I don't think you even need to check played since you are making separate function calls and the audio isn't looping.

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

82 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Object not casting shadow properly 1 Answer

Game Show Happy Birthday whenever Birthday Will Come 1 Answer

Falling Object Trigger Problem 1 Answer

How to use light Range or intensity as a trigger? 0 Answers

Making an object with a grid of very small blocks. 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