Hey guys, I’m a bit confused to why my sound is not playing when I go through an object
using UnityEngine;
using System.Collections;
public class Jewels : MonoBehaviour
{
public GUIText jewelsText;
public GUIText winText;
public AudioClip Pickup;
private int jewels;
// Use this for initialization
void Start ()
{
jewels = 0;
SetJewelsText();
winText.text = "";
}
void OnTriggerEnter(Collider other)
{
if(other.gameObject.tag == "Pickups")
{
other.gameObject.SetActive(false);
jewels = jewels + 1;
SetJewelsText();
}
if (Pickup)
{
audio.clip = Pickup;
audio.Play();
}
}
void SetJewelsText()
{
jewelsText.text = "jewels:" + jewels.ToString();
if(jewels >=20)
{
winText.text = "You Collected all the jewels!";
}
}
}
Are you sure your Collider is set to isTrigger?
– TanshaydarI just did the Roll a Ball Tutorial and am trying to figure out how to do the same thing. Call a sound when I pick up each cube. Does this code need to be placed in the "Player" script I have currently or can I make a new Pick Up's script ? Thanks, Kristi
– kristi-knupp