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 cozmoziz · May 03, 2011 at 04:46 PM · audioscenemusicisplaying

audio.isPlaying always returns false

I am trying to set music to play throughout the game and continue between scenes with an empty gameobject that has the script below attached on my main scene. It starts fine and when I move to other scenes it continues to play, but when I switch scenes back from another scene back to the main scene it plays a second instance. I am checking for isPlaying, but it always returns false. Is this because the gameobject is a new instance so I am not checking the original instance that is first created when the game starts?

function Awake () {

 //Also checked for gameMusic as a boolean, but that didn't work either
 //var gameMusic : GameObject = GameObject.Find("gameMusic");
 //if(gameMusic){ audio.Play(); }

 Debug.Log("is audio playing - " + audio.isPlaying);

 if (!audio.isPlaying) {
     Debug.Log("audio was not playing so it was started");
     audio.Play();
 }

 DontDestroyOnLoad (transform.gameObject);

}

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 cozmoziz · May 03, 2011 at 05:29 PM 0
Share

Sorry, I used to check for game$$anonymous$$usic as a boolean. Just forgot to take that out.

So original code was

if (game$$anonymous$$usic) { audio.Play(); }

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jesse Anders · May 03, 2011 at 05:21 PM

First of all, you search for a game object named 'gameMusic', but then you never use that reference.

Also, if you reload the scene that the 'game music' object is part of, a new instance of that object will be created. If you want only one 'game music' object, it should be part of a scene that's only loaded once (e.g. an 'intro' scene or something of that sort).

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

Answer by cozmoziz · May 03, 2011 at 06:29 PM

I found the answer with the help of using singleton's from this post. I've posted my answer here.

http://answers.unity3d.com/questions/24519/using-singleton-for-background-music

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

No one has followed this question yet.

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

Playing Music After Seconds Works, But When Scene Reloads, Script Doesn't Work 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