Answer the question
In order to leave comments, you need to log in
How can I make the sound play as soon as you touch the key, and not when you release it?
The essence of the question is this:
I made a piano on android, everything works fine, but I ran into one problem, When you press a key, the sound is not played, but as the key is released, it is played. How can I make the sound play as soon as you touch the key, and not when you release it?
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioManenger : MonoBehavior
{
private AudioSource AudioNotes;
[Header("Notes")]
[SerializeField] private AudioClip[] Notes = new AudioClip[20];
void Start()
{
AudioNotes = GetComponent();
}
public void PlaySound(int numberNotes)
{
AudioNotes.PlayOneShot(Notes[numberNotes]);
}
}
Answer the question
In order to leave comments, you need to log in
I can't see from the code where you have the click event. I know for sure that you can, for example, use https://docs.unity3d.com/2019.1/Documentation/Scri...
and then when the button is pressed, the event will be sent at the moment of pressing, and not after releasing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question