Play on Click GUI [ Unity ]

Posts 1–2 of 2 · Page 1 of 1
Play on Click GUI [ Unity ]
Well i got bored an decided to share a Play on Click GUI Script, Basically what it does is when you click it plays an audio source for a short period of time. You can adjust it to your preference if you like or add on to it. I'am Still learning how to code GUI in unity i will share as many scripts as i can.

Code:
var model : GameObject;
var track : AudioSource;
 
function OnGUI () {
 
  //background box
  GUI.Box (Rect (10,130,100,90), "Sounds");
 
  //Make first button
  if (GUI.Button (Rect(20,160,80,20),  "Go")){
   audio.clip = track;
        audio.loop = false;
 
      audio.Play();
 
  }
 
  //Make second button
  if (GUI.Button (Rect(20,190,80,20),  "Stop")){
 
      audio.Stop();
 
  }
}
Paste Bin Verison

http://pastebin.com/28r0J5JQ
Good to see you sharing your progress and work that you've accomplished with this
Posts 1–2 of 2 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us