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 Tommy 1 · Feb 29, 2012 at 12:39 PM · audiostop

Audio won´t stop

Hi! I have a level (2) where you choose music to be played in the next level (3). You can return back to this level (2) with a (GUI button BACK) in lvl 3. The back GUI button sends a message "ShutDownSound" (to this object and this code where all music is stored in vars) before lvl (2) is loaded. I am very new to coding so this may not be good code, but it mainly works (I get the random sound playing as intended for lvl 3), I can return back the FIRST time and in that case the music stops (as expected), but if I goto lvl 3 again and return a SECOND time, then the music keeps playing.. whyyyy? :-(

// This code is put on an object in LVL 2, with DontDestroyOnLoad code.

function shutDownSound (){audio.Stop();}

// called from another (levels BACK button) when returning here. // called before Application.LoadLevel ("2");

function Awake () { DontDestroyOnLoad (transform.gameObject);}

var rmusik : int; // Defines by a number which type of music is played.

function musik1(){
rmusik = 1;
rCallmusik(); } // called with sendmessage from a GUI script. "Rock music".

function musik2(){
rmusik = 2; rCallmusik(); } // called with sendmessage from a GUI script. "Pop music".

var sound1: AudioClip; var sound2: AudioClip; var sound3: AudioClip; var sound10: AudioClip; var sound11: AudioClip; var sound12: AudioClip;

var rmusikTrack : int;
// a var to temporary store a randomly chosen song.

function rCallmusik (){ if (rmusik==1){ rmusikTrack = Random.Range(1,4);
if (rmusiktrack==1){ if (audio.isPlaying) return; audio.clip = sound1; audio.Play();}

if (rmusikTrack==2){ if (audio.isPlaying) return; audio.clip = sound2; audio.Play();}

if (rmusikTrack==3){
if (audio.isPlaying) return; audio.clip = sound3; audio.Play();} }

if (rmusik==2){ rmusikTrack = Random.Range(10,13); if (rmusikTrack==10){ if (audio.isPlaying) return; audio.clip = sound10; audio.Play();}

if (rmusikTrack==11){
if (audio.isPlaying) return; audio.clip = sound11; audio.Play(); }

if (rmusikTrack==12){ if (audio.isPlaying) return; audio.clip = sound12; audio.Play(); } }

// The AudioSource attached to this object has LOOP unchecked in the inspector.

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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Pause Menu Audio 1 Answer

How to stop Audio not all?? 0 Answers

java.lang.IllegalStateException: stop() called on uninitialized AudioTrack. 1 Answer

How to Stop all audio 10 Answers

How to stop audio 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