- Home /
Touch Piano
I have a piano layout in unity and I would like to when I touch the keys (tap) it plays a sound until I release. (Like a piano).
I am new to Unity and don't have any code yet.
Thanks in advance!
Have you looked into Input.touches and TouchPhase. There are examples in the docs, and many many more questions, answers and tutorials around about handling touch input. Google is definitely your friend for this.
Thankyou for your help. Has anyone got any code as I am not very good at looking at docs and creating code.
The docs give pretty good code samples. If you aren't ready to handle that yet, you should probably shelve this idea for the time being and take on some unity/program$$anonymous$$g basic tutorials. This site isn't a place to ask for scripts, and it would really benefit you to learn the basics, as it only gets harder from here. Good luck.
Answer by Narv · Sep 01, 2013 at 10:18 PM
Is this 2d or 3d?
also, place an collided in each key object and a script that on the update function checks the input.tocuhes. Then raycast on touch using camera.main.screenpointtoray and see what collided it hits. Then based on which one it hits, play a sound or whatever it is you wish to do.
It is 2d. I am using planes for the keys but to make it look 2d a orthographic camera.
Your answer