Play audio C# [fixed]

Managed to get it fixed, how… no idea.

In the Unity documentation, the example scripts usually have a dropdown list where it says (f.ex) Javascript, where you can switch to C# or Boo.

http://unity3d.com/support/documentation/ScriptReference/AudioSource.Play.html

Should be no exception.

First thing: to which object this script is attached? If this object is too far from the camera, the sound may be heard too low, or not be heard at all. You must also attach an AudioSource to this object and set its Clip property to the desired sound, or you will get Null Reference errors (pay attention to the Console!).

An alternative to avoid all this setup is to use PlayClipAtPoint:

public AudioClip errorSound; // drag the desired sound here

void OnLeftClickUp(SimonLightPlate.eType color)
{
    ...
    if (!VerifySequence()) 
    {
        AudioSource.PlayClipAtPoint(errorSound, Camera.main.transform.position);
        ResetGame();
    }
    ...

This will instantiate a temporary AudioSource and play the sound at the camera position (where the game “ears” usually are), destroying automatically the AudioSource when the sound finishes.

I am now trying it with audio.clip = (AudioClip)Resources.Load("wrong"); however now I get an error that I have not attached an audio source to my object, but I have!

Could someone help me with this problem?

	public AudioClip wrong; 

    void OnLeftClickUp(SimonLightPlate.eType color)
    {
		if (currentState == eState.WAITING_FOR_USER) 
		{
			lightPlates[(int)color].plate.renderer.enabled = false;
			
			if (!VerifySequence()) 
			
			{
				audio.clip = (AudioClip)Resources.Load("wrong");
				
				ResetGame();
			}
			else
			{
				if (clickedSequence.Count == sequenceCount) 
				{
					currentState = eState.THINKING;
					clickedSequence.Clear();
				}
			}
		}
       
    }