When my snowboarder crosses the finish line it triggers the sound effect plays twice. I found a work around by creating a bool variable and using it in an if statement, but I would like to not have to do that if possible. Here’s the code I wrote for the finish line script that caused the sound effect t play twice:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class FinishLine : MonoBehaviour
{
[SerializeField] float delayAmount = 0.5f;
[SerializeField] ParticleSystem finishEffect;
private void OnTriggerEnter2D(Collider2D other) {
if(other.tag == "Player")
{
finishEffect.Play();
GetComponent<AudioSource>().Play();
Invoke("ReloadScene", delayAmount);
}
}
void ReloadScene()
{
SceneManager.LoadScene(0);
}
}