Answer the question
In order to leave comments, you need to log in
How to solve the problem with playing sound through a key?
I wrote the code, I turn on the game, but there is no sound when I press the key. What to do?
public class sosjn : MonoBehaviour
{
private AudioSource AudioNotes;
[Header("Массив нот")]
[SerializeField] private AudioClip[] Notes = new AudioClip[4];
void Start()
{
AudioNotes = GetComponent<AudioSource>();
}
public void Update(int numberNotes)
{
if (Input.GetKeyDown(KeyCode.S))
{
AudioNotes.clip = Notes[numberNotes];
AudioNotes.Play();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question