I’m doing a menu for my game and I don’t know how to play a sound after the mouse pass through it…
I just made it change the color and load the next level.
for example.
using UnityEngine;
using System.Collections;
public class play : MonoBehaviour {
public bool sair = false;
void OnMouseEnter ()
{
renderer.material.color = Color.blue;
}
void OnMouseExit ()
{
renderer.material.color = Color.white;
}
void OnMouseDown ()
{
if (sair)
{
Application.Quit();
}
else
{
Application.LoadLevel(1);
}
}
}
You need to have an AudioSource attached to your GameObject with an AudioClip assigned to it. Then you simply call Play() on the audio source within the OnMouseEnter() event. You will also need an AudioListener most likely attached to your main camera.
You can simply use audio.Play() to start playing the sound. Add an AudioSource to the menu object and set its Clip field to the desired sound, then add the instruction audio.Play() to the OnMouseEnter event - like this:
void OnMouseEnter ()
{
renderer.material.color = Color.blue;
audio.Play();
}
HINT: It’s better to uncheck the 3D sound property in the clip (click the audio clip in the Project view to access its properties)
hehe…thanks…it worked…!
I also put an song to play when the scene is loaded to stay as background music…
=D