Note: It's a 2D Game
I'm trying to get an audio clip to play when the Character comes into contact with an object that has a Box Collider around it.
I've tried OnTrigger/OnCollision methods but neither are playing any sound. I've also tried many solutions online but still no sound on collision. My Clip works on Awake, but not as intended.
Checklist:
- The Player has a "Player" tag.
- The Player has a Rigidbody 2D and a Collider 2D
- The Oject Collider has 'Is Trigger' ticked
- The Object has an AudioSource
- The Object has an Audio Script
- The Object has a Box Collider 2D for the collision around it
- The Audio Clip is attached to the AudioSource component
Here's the current Script (Attached to Object): I'd be very thankful!
public class Audio : MonoBehaviour
{
public AudioSource audioClip;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == "Player")
{
audioClip.Play ();
}
}
}
OnTriggerEnter? Do you use that orOnTriggerEnter2D? - Gunnar B.