Hey i need to play a sound when i enter the trigger before the scrtipt destroy the gameobject but i cant figure out how, heres my script
using UnityEngine;
using System.Collections;
public class Pickup : MonoBehaviour
{
public enum Item
{
Flashlight,
Battery
}
public Item item;
void OnTriggerEnter()
{
if(item == Item.Flashlight)
{
HUD.HasFlashlight = true;
}
else
HUD.BatteryCount++;
Destroy(gameObject);
}
}
Try this, StickyDream:
using UnityEngine;
using System.Collections;
public class Pickup : MonoBehaviour {
public enum Item { Flashlight, Battery }
public Item item;
public AudioClip flashlightSound;
public AudioClip batterySound;
void OnTriggerEnter()
{
if(item == Item.Flashlight)
{
AudioSource.PlayClipAtPoint(flashlightSound, transform.position, 1);
HUD.HasFlashlight = true;
}
else
HUD.BatteryCount++;
AudioSource.PlayClipAtPoint(batterySound, transform.position, 1);
Destroy(gameObject);
You need an AudioSource. You will need a reference to an AudioSource that has the AudioClip you want to play assigned to it. Then you can call play of the audio source.