AudioSource not playing sound, Editor crashes?

Hi UnityAnswers,

I am trying to play a sound when the player walks into the cube? At the moment the game crashes when the player collides with the cube?

Any ideas, help, suggestions would be appreciated.

alt text

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Trigger : MonoBehaviour 
{
	public GameObject guiObject;
	private Question1 guiScript;
	public AudioSource collision;

	
	void Awake ()
	{
		guiScript = guiObject.GetComponent<Question1> ();
		guiScript.enabled = false; //Turn off the script, so the OnGUI function doesn't draw the question window
	}

	void OnTriggerEnter (Collider other)
	{
		if (collision)
			audio.Play();
		guiScript.enabled = true;
		Destroy (this.gameObject);
	}
}

Change lines #20-21 to this:

if (collision != null) collision.Play();

And my advise to you rename your AudioSource variable to something more obvious like cubeAudio or something, collision isn’t the best name you could come up with really.