Audio Trigger

Hello,

Lately, I’ve been having trouble adding an audio trigger to one of my buttons. You see, what I want to do is when the mouse rolls over a button, I want it to make a sound. I already have the sound file called “Roll.” Now, I just want to add the trigger. Here’s the code so far. BTW, it’s in C#.


using UnityEngine;
using System.Collections;

public class HomeButton : MonoBehaviour 
{
	void OnMouseEnter()
	{
		transform.Translate(0, 0, 1);
		renderer.material.color = Color.blue;
	}
	
	void OnMouseExit()
	{
		transform.Translate(0, 0, -1);
		renderer.material.color = Color.white;
	}
	
	void OnMouseDown()
	{
		if(isQuit)
		{
			Application.Quit();
		}
		else
		{
			Application.LoadLevel("Menu");
		}
	}
}

Please respond back ASAP.

Regards,
Silent-11

Well, what you have almost covers it. You should add an AudioSource component to the object to which that script is attached, set it up to play the sound, and then add the line

audio.Play();

inside the OnMouseEnter callback.

Remember that you may want to make the sound 2D, so that it ignores the listener position. This is probably more useful for interface sounds.

Okay thanks! BTW, is there anything I should put in the parameters?

Okay thanks!