I
I
Ilya Alexandridi2021-05-26 13:18:15
Android
Ilya Alexandridi, 2021-05-26 13:18:15

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

2 answer(s)
V
Vitaly Kachan, 2021-05-26
@MANAB

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.

F
freeExec, 2021-05-26
@freeExec

https://docs.unity3d.com/ScriptReference/Input.Get...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question