on text click

Hi! I have request,can you please edit my code.I am making simple soundboard,but i wan’t to make code work on audio click,not on mouse enter.Like,when you click on text,changes red and starts to play audio,when audio ends,text changes to color white again.

#pragma strict

var isQuitButton = false;

var sound : AudioClip;

function OnMouseEnter()
{
renderer.material.color = Color.red;
audio.PlayOneShot(sound);
}

function OnMouseExit()
{
renderer.material.color = Color.white;
audio.Stop();
}

*Bump

There isn’t any event that happens when a sound is done playing. However, there is a length for the audio clip, so you could use that.

function OnMouseDown()
{
renderer.material.color = Color.red;
audio.PlayOneShot(sound);
waitForAudio(audio.clip.length);

}
function waitForAudio( time:float){
yield WaitForSeconds(time);
//change color back
renderer.material.color = Color.white;
}

I need code with OnMouseClick.For javascript please,i am begginer in coding.

I changed the code for you, but you need to take some tutorials.

Can you please someone edit code,to make it like,when you click audio 2x it plays at the same time(multisound of one audio)Can you please fix it,i won’t these multisounds.And i want when i click somewhere else(except box collider) audio stops sounding.I hope you understood my bad english :slight_smile:

#pragma strict

var isQuitButton = false;

var sound : AudioClip;

function OnMouseDown()
{
renderer.material.color = Color.red;
audio.PlayOneShot(sound);
waitForAudio(audio.clip.length);

}
function waitForAudio( time:float){
yield WaitForSeconds(time);
//change color back
renderer.material.color = Color.white;
}

If you don’t want to actually write a game, then don’t. Otherwise, read the manual and do some tutorials.