Hi there, I’m new to Unity and have been trying to write a few simple codes for a 2D platformer to trigger audio, making the audio play or stop when entering or exiting the colliders that they’re assigned to. I’ve tried looking at other answers and tutorials but I just can’t seem to get it right. Any feedback or help would be greatly appreciated, thanks.
Here’s what I’ve got so far to play music once the player comes into contact with the collider (player is named ‘hero’):
using UnityEngine;
using System.Collections;
public class AudioStop : MonoBehaviour {
// Use this for initialization
void Start () {
void OnTriggerEnter2D (2DCollider other)
{
if(other.gameObject.tag == "hero")
{
audio.Play(MainTheme);
}
}
}
// Update is called once per frame
void Update () {
}
}
And how would I go about writing something to stop the music once entering a collider?