Question by
B00657332 · Dec 09, 2015 at 03:59 PM ·
c#audiosourceaudioclipsound effects
How to add collection sound to watering can?
I would like to add a sound effect when the watering can is collected in the game. It is a health pick up as well.
I've tried looking up different code but none of it works. Any help would be welcome The code for the watering can (health pick up) is below...The sound effect I wish to use is called 'wateringCanCollected' and is in Unity already, but I don't know how to add it to the script
Blockquote
using UnityEngine; using System.Collections;
public class AddHealthToPlayer : MonoBehaviour {
int HealthPack = 10;// Amount player health will go up by.
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Player")
{
CharacterManager.Instance.characterData.health += HealthPack;//Update player health when watering can is picked up
if (CharacterManager.Instance.characterData.health > CharacterManager.Instance.MaxHealth) CharacterManager.Instance.characterData.health = CharacterManager.Instance.MaxHealth;//Check if health is at maximum when player picks up watering can, keep health at MaxHealth
Destroy(gameObject);//Watering can will disappear if player runs into it
print(CharacterManager.Instance.characterData.health);//Print player health
}//if
}//OnTriggerEnter2D
}//AddHealthToPlayer
Blockquote
Comment