x


GUI help! I have no idea why my code this isn't working!

var clickSound : AudioClip;

function OnGUI(){
if(GUI.Button(Rect(25, 370, 150, 25), GUIContent ("Singleplayer", "SingleTool"))){
 if(GUI.tooltip == "SingleTool"){
   audio.PlayOneShot (clickSound);
      }
   }
}

I think it was because I did the code wrong, yes?

more ▼

asked Aug 17 '11 at 11:40 AM

julz11 gravatar image

julz11
1 2 3 4

where is the error at?

Aug 17 '11 at 11:55 AM AdamEstone
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Have you tried clicking on the button. The way you have the code set up would only play the sound when you click it, since you have the code to play the audio inside the if(GUI.Button...) statement. Try this if you want the sound to play when you hover over the button:

var clickSound : AudioClip;

function OnGUI(){ GUI.Button(Rect(25, 370, 150, 25), GUIContent ("Singleplayer", "SingleTool"))

if(GUI.tooltip == "SingleTool"){ audio.PlayOneShot (clickSound); } }

Note: I am new to Unity so I may be completely wrong.

more ▼

answered Aug 18 '11 at 05:58 PM

Spartan301 gravatar image

Spartan301
1 1

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

there were no errors everything was fine, I attached my sound to the var and everything but it did not play the sound when I hovered over the gui button!

more ▼

answered Aug 17 '11 at 12:05 PM

julz11 gravatar image

julz11
1 2 3 4

(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:

x3813
x303

asked: Aug 17 '11 at 11:40 AM

Seen: 633 times

Last Updated: Aug 18 '11 at 05:58 PM