Hi everyone so i have this script and it doesn’t seem to work for some reason
i don’t know what i did wrong here so could someone please help me out?
this is my script
using System.Collections;
public class MenuObject: MonoBehaviour {
// Use this for initialization
void OnMouseEnter () {
renderer.material.color = Color.blue;
}
void OnMouseExit () {
renderer.material.color = Color.white;
}
void OnMouseDown () {
Application.LoadLevel("LevelSelectScene")
{ Audio.PlayOneShot("Click"); }
Unity says the "void OnMouseDown () {
Application.LoadLevel(“LevelSelectScene”) { Audio.PlayOneShot(“Click”); }"
part is wrong
There’s an extra { in OnMouseDown, and PlayOneShot expects an AudioClip variable, not a sting - it should be like this:
public AudioClip clickSound; // set this variable in the Inspector
void OnMouseDown () {
audio.PlayOneShot(clickSound);
Application.LoadLevel("LevelSelectScene");
}
Notice that the click sound may not be heard at all because the scene objects are destroyed before loading the new scene. If this happens, make OnMouseDown a coroutine in order to use a suitable delay before LoadLevel:
public AudioClip clickSound; // set this variable in the Inspector
IEnumerator OnMouseDown () { // declare OnMouseDown as a coroutine
audio.PlayOneShot(clickSound);
yield return new WaitForSeconds(clickSound.length); // wait clip duration
Application.LoadLevel("LevelSelectScene"); // load the new scene
}
im not sure what the problem is now but unity says that there is an parsing error with this code
using System.Collections;
public class MenuObject: MonoBehaviour {
// Use this for initialization
void OnMouseEnter () {
renderer.material.color = Color.blue;
}
void OnMouseExit () {
renderer.material.color = Color.white;
}
public AudioClip click; // set this variable in the Inspector
void OnMouseDown () {
audio.PlayOneShot(Click);
Application.LoadLevel(“LevelSelectScene”);
}