Hello, Visual Code is telling me that “GetComponent<AudioSource” does not work in the current context, and I am pretty sure that I followed the steps correctly. I am not sure why this is happening and how to fix it.
“”"
using UnityEngine;
using UnityEngine.SceneManagement;
public class CrashDetector : MonoBehaviour
{
[SerializeField] float loadDelay = 0.5f;
[SerializeField] ParticleSystem crashEffect;
[SerializeField] AudioClip crashSFX;
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Ground")
{
crashEffect.Play();
GetComponent<AudioSource>.PlayOneShot(crashSFX);
Invoke("ReloadScene", loadDelay);
}
}
void ReloadScene()
{
SceneManager.LoadScene(0);
}
}
“”"