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 /
This question was closed May 08, 2016 at 03:54 AM by ReflexGames for the following reason:

Taking too long for replys, will ask a new quesion.

avatar image
0
Question by ReflexGames · May 02, 2016 at 03:40 AM · audioscenemusicreload

Playing Music After Seconds Works, But When Scene Reloads, Script Doesn't Work

Hello!

I have a probably really easy question but I have no Idea what do to. In my scene, I don't have the music start or a GUI text disappear in till three seconds after the scene starts. So when I start my scene, everything works, but if I die, then I go back to the Main Menu, where I can select the same scene and try it again, but for some reason, the music starts right away, even though the GUI text still stays for three seconds then disappears. Here is the music script, don't know if it will be much help.

 var song : AudioSource;
  
 function Update () {
      
     if (!song.isPlaying && Time.time >= 3) {
         song.Play();
     }
 }

 

Any Thoughts?

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
0

Answer by UsmanAbbasi · May 02, 2016 at 02:21 PM

Time.time gives you the time since the projects is started. So when you reload your scene, Time.time is always greater than 3 which causes the condition to be true and it plays the music.

  • You need to have another variable to store your time since the scene is started and always initialize it to 0 in Start() method.

  • Or you can use Invoke() to play song after 3 seconds like this.

         void Start()
         {
             Invoke("PlayMusic" , 3);
         }
         
         void PlayMusic()
         {
             song.Play();
         }
    
    
    
Comment
Add comment · Show 5 · 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 ReflexGames · May 06, 2016 at 04:17 AM 0
Share

Ok, two things. Do I add your script to my script, or do I delete $$anonymous$$e and put yours there? Also, I am getting two errors, even if I Delete my script or not, saying "Void is not a valid $$anonymous$$acro".

Any $$anonymous$$gestions?

avatar image aditya ReflexGames · May 06, 2016 at 07:27 AM 0
Share

because letter v of your void is capital, make it small

avatar image ReflexGames aditya · May 07, 2016 at 08:37 PM 0
Share

It is a small letter.

 var song : AudioSource;
   
 function Update () {
       
     if (!song.isPlaying && Time.time >= 3) {
         song.Play();
     }
 }
 
 void Start()
 {
     Invoke("Play$$anonymous$$usic" , 3);
 }
      
 void Play$$anonymous$$usic()
 {
     song.Play();
 }
Show more comments
avatar image UsmanAbbasi · May 08, 2016 at 05:31 AM 0
Share

Add this code in your script to run it.

Follow this Question

Answers Answers and Comments

47 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

Related Questions

Keep audio playing even though I reset the scene 5 Answers

Changing Continuous Audio Between Scenes 0 Answers

I have a audio source in one scene, I want it to continue when entering next scene 1 Answer

Change music between scenes 1 Answer

audio.isPlaying always returns false 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