Hello.
I’ve created a topic already, but was unable to do.
I do piano. I did push through OnMouseDown. I need to make a multi-touch. I have tried in different ways, but that does not work, tell me please ![]()
Hello.
I’ve created a topic already, but was unable to do.
I do piano. I did push through OnMouseDown. I need to make a multi-touch. I have tried in different ways, but that does not work, tell me please ![]()
Don’t use OnMouseDown.
Instead in the Update() function you should read your input from the Input.touches[ ] array.
Each Touch object in that array contains everything you need to know about the touches at that particular frame in time.
You would need to correlate that to a particular key using either raycasting into the scene, or perhaps checking the rectangle for a particular piano key.
@Kurt-Dekker Halo sir…
I did it as per ur suggestion…
Could you kindly rectify the problem if any in the code below.
void Update ()
{
if (Input.touchCount > 0)
{
foreach(Touch touch in Input.touches)
{
if(touch.phase==TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay (touch.position);
if(Physics.Raycast(ray,out hit))
{
if(hit.collider.gameObject.tag==“Box1”)
{
hit.collider.gameObject.GetComponent ().pitch = Mathf.Pow (2f, semitone_offset / 12.0f);
hit.collider.gameObject.GetComponent ().Play ();
}
}
}
}
}
}
This somehow doesn’t work…I have tagged the piano key as Box1… I am trying to access the audio source of the piano collider …
Firstly, check this thread for how to post code on the forums for future reference: Using code tags properly
Next, do you get any errors? Does the raycast hit?
My other suggestion would be to use the IPointerClickHandler interface, which entails:
@methos5k Thanks methos. Will work on that and post if its done. I implemented the OnPointerClick method of IPointerClickHandler… I added a breakpoint at Input.touchCount condition but somehow the condition is not checked and the control exits…
Okay, I forgot to mention a couple of things:
Just try printing ‘Debug.Log(“This worked.”)’ to see if the “click/touch” registers. ![]()
Let me know if that works.
Thanks @methos5k . The earlier solution of Ipointerclickeventhandler worked for me…