x


Help with GUI clicking ???

Hi guys i just wrote a script which plays a song when the GUI is clicked. The problem that i am having is that when i click the GUI button again it plays the song again and it starts to overlap the song that is playing and it sounds horrible. Now what i want to do is if the song is playing and the GUI button is clicked again i dont want it to play the song again if its playing.

here is the script that i wrote:

 var MyAudio : AudioClip;
  function OnGUI () 


 if (GUI.Button (Rect(10, 20,105,20),  "Play Track 1 ( Enter) ")){

 audio.PlayOneShot(MyAudio);

 } 
 }

thanks in advance :)

more ▼

asked Feb 23 '11 at 06:33 AM

MC HALO gravatar image

MC HALO
878 74 94 111

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You could use:

if (!audio.isPlaying){
  audio.clip = MyAudio;
  audio.Play();
}
more ▼

answered Feb 23 '11 at 01:07 PM

efge gravatar image

efge
5.1k 5 14 38

hey efge thank you very much that solved the problem :)

Feb 24 '11 at 02:38 AM MC HALO
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3748
x3697
x790
x224
x8

asked: Feb 23 '11 at 06:33 AM

Seen: 675 times

Last Updated: Feb 23 '11 at 07:09 AM