So far I have tried:
public AudioClip PotionPickup1;
public AudioClip PotionPickup2;
public AudioClip OrbPickup;
public AudioSource PickupAudio;
void Start() {
GameObject HealthPotionLarge = GameObject.Find (“HealthPotionLarge”);
GameObject HealthPotionSmall = GameObject.Find (“HealthPotionSmall”);
GameObject ManaPotionLarge = GameObject.Find (“ManaPotionLarge”);
GameObject ManaPotionSmall = GameObject.Find (“ManaPotionSmall”);
GameObject ManaOrbLarge = GameObject.Find (“ManaOrbLarge”);
HealthPotionLarge.gameObject.AddComponent<AudioSource> ();
HealthPotionSmall.gameObject.AddComponent<AudioSource> ();
ManaPotionLarge.gameObject.AddComponent<AudioSource> ();
ManaPotionSmall.gameObject.AddComponent<AudioSource> ();
ManaOrbLarge.gameObject.AddComponent<AudioSource> ();
PotionPickup1 = Resources.Load ("Potion_Pick-Up_v1") as AudioClip;
PotionPickup2 = Resources.Load ("Potion_Pick-Up_v2") as AudioClip;
OrbPickup = Resources.Load ("Orb_Pick-Up") as AudioClip;
}
void OnTriggerEnter(Collider collision) {
if (collision.tag == "Player") {
Player p = collision.gameObject.GetComponent<Player>();
switch (type) {
case ItemType.SmallHealthPotion:
case ItemType.SmallManaPotion:
case ItemType.LargeHealthPotion:
case ItemType.LargeManaPotion:
case ItemType.SmallKey:
if(Random.Range(0,1) == 0){
//audio.PlayOneShot (PotionPickup1, .7f);
PickupAudio.clip = PotionPickup1;
PickupAudio.loop = false;
PickupAudio.playOnAwake = false;
PickupAudio.Play();
}else {
//audio.PlayOneShot (PotionPickup2, .7f);
PickupAudio.clip = PotionPickup2;
PickupAudio.loop = false;
PickupAudio.playOnAwake = false;
PickupAudio.Play();
}
if (!p.InventoryFull || item.GetType() == typeof(Key)) {
item.Pickup(ref p);
Destroy(gameObject);
}
break;
case ItemType.LargeHealthOrb:
case ItemType.MediumHealthOrb:
case ItemType.SmallHealthOrb:
if (p.Health < p.MaxHealth) {
((HealthOrb)item).Pickup(ref p);
audio.PlayOneShot (OrbPickup, 0.7f);
Destroy(gameObject);
}
break;
case ItemType.LargeManaOrb:
case ItemType.MediumManaOrb:
case ItemType.SmallManaOrb:
if (p.Mana < p.MaxMana) {
((ManaOrb)item).Pickup(ref p);
audio.PlayOneShot (OrbPickup, 0.7f);
Destroy(gameObject);
}
break;
***end code I also need the same thing to happen for multiple gameobjects (different potion variations), but its not working, the most recent test i did it gave me this error:
UnassignedReferenceException: The variable PickupAudio of ‘ItemHolder’ has not been assigned.
You probably need to assign the PickupAudio variable of the ItemHolder script in the inspector.
ItemHolder.OnTriggerEnter (UnityEngine.Collider collision) (at Assets/Scripts/Item/Pickup/ItemHolder.cs:89)
please and thank you so much for any help