Hi I wrote a script to play a sound after the if statement activates, but nothing happens. I’ve tried a lot of different things. Here is the script I’m using:
using UnityEngine;
using System.Collections;
public class TimerScript : MonoBehaviour
{
public GUIText clockTime;
public GUIText loseMessage;
public GameObject rift;
public GameObject tryAgainButton;
public GameObject returnButton;
public Rigidbody kineticBody;
private float timeLeft;
public AudioClip[] loseSound;
void Start ()
{
kineticBody = GetComponent<Rigidbody> ();
timeLeft = 30;
clockTime.text = "Time: 00:" + timeLeft.ToString();
loseMessage.text = "";
}
void Update ()
{
timeLeft -= Time.smoothDeltaTime;
clockTime.text = "Time: 00:" + timeLeft.ToString ();
if (timeLeft <= 0)
{
loseMessage.text = "You Failed!";
clockTime.text = "Time: 00:00";
tryAgainButton.SetActive(true);
returnButton.SetActive(true);
kineticBody.isKinematic = true;
rift.SetActive(false);
PlaySound(0);
}
}
void PlaySound (int noise)
{
audio.clip = loseSound[noise];
audio.Play ();
}
}
I’m new to Unity so I’m not sure what I’m doing wrong.