Question by
MrGistarb · Apr 27, 2016 at 05:19 PM ·
audioaudiosourceaudioclipaudio.play
Pick Up Sound
I'm trying to play a sound when a certain object is collected. Any help would be appreciated.
My Code:
using UnityEngine; using UnityEngine.UI; using System.Collections;
public class PlayerPickUp : MonoBehaviour {
//public float speed;
public Text countText;
public Text winText;
public GameObject Exit;
public GameObject spikewalldoor;
//private Rigidbody rb;
private int count;
void Start ()
{
// rb = GetComponent(); count = 0; SetCountText (); winText.text = ""; }
void FixedUpdate ()
{
//float moveHorizontal = Input.GetAxis ("Horizontal");
//float moveVertical = Input.GetAxis ("Vertical");
//Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
//rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ( "Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Collect 245 Cubes: " + count.ToString ();
if (count >= 245)
{
winText.text = "Level Complete!";
Exit.gameObject.SetActive (true);
spikewalldoor.gameObject.SetActive (false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Why won't my second Audio Source play? 0 Answers
Audio Clip Error. 2 Answers
Audio won't play, no matter what code or method I try 0 Answers
How to reduce delay when playing sound 0 Answers
Audio playing at hightspeed and simoultanesly various times! 1 Answer