Hi,
I'm using the FingerManager script found on Unitywiki and it works great, but I need to get the touch position and this script is only sending touch moves, began and cancels. Any suggestions on how to do that? Code below is .cs and I use void FingerBegin (Touch evt) { from a gameobject with a collider to see when a button is pressed. This works with multitouch....Thx for any help!
using UnityEngine;
using System.Collections;
public class Finger {
public Touch touch;
public bool moved = false;
public ArrayList colliders = new ArrayList();
}
public class FingerManager : MonoBehaviour {
public ArrayList fingers = new ArrayList();
void Update () {
RaycastHit[] hits;
foreach (Touch evt in Input.touches) {
// if (evt.phase==TouchPhase.Began) {
if (evt.phase==TouchPhase.Began || evt.phase==TouchPhase.Moved ) {
Finger finger = new Finger();
finger.touch = evt;
Ray ray = Camera.main.ScreenPointToRay(evt.position);
hits = Physics.RaycastAll(ray);
foreach (RaycastHit hit in hits) {
finger.colliders.Add(hit.collider);
GameObject to = hit.collider.gameObject;
to.SendMessage("FingerBegin",evt,SendMessageOptions.DontRequireReceiver);
}
fingers.Add(finger);
}
else if (evt.phase==TouchPhase.Moved) {
for (int i=0;i<fingers.Count;++i) {
Finger finger = (Finger)fingers*;*
*if (finger.touch.fingerId==evt.fingerId) {*
*finger.moved = true;*
*foreach (Collider collider in finger.colliders) {*
*if (collider==null) {continue;}*
*GameObject to = collider.gameObject;*
*to.SendMessage("FingerMove",evt,SendMessageOptions.DontRequireReceiver);*
*}*
*}*
*}*
*}*
*else if (evt.phase==TouchPhase.Ended || evt.phase==TouchPhase.Canceled) {*
*Ray ray = Camera.main.ScreenPointToRay(evt.position);*
*hits = Physics.RaycastAll(ray);*
*for (int i=0;i<fingers.Count;) {*
_Finger finger = (Finger)fingers*;*_
_*if (finger.touch.fingerId==evt.fingerId) {*_
_*foreach (Collider collider in finger.colliders) {*_
_*if (collider==null) {continue;}*_
_*bool canceled = true;*_
_*foreach (RaycastHit hit in hits) {*_
_*if (hit.collider==collider) {*_
_*canceled = false;*_
_*GameObject to = collider.gameObject;*_
_*to.SendMessage("FingerEnd",evt,SendMessageOptions.DontRequireReceiver);*_
_*}*_
_*}*_
_*if (canceled) {*_
_*GameObject to = collider.gameObject;*_
_*to.SendMessage("FingerCancel",evt,SendMessageOptions.DontRequireReceiver);*_
_*}*_
_*}*_
<em>_fingers *= fingers[fingers.Count-1];*_</em>
<em>_*fingers.RemoveAt(fingers.Count-1);*_</em>
<em>_*}*_</em>
<em>_*else {*_</em>
<em>_*++i;*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*}*_</em>
<em>_*```*_</em>
@ Harmless Ahhh, Thank You. @JW, Will do, where is that button though?
– anon56119378Hi there, I added Vector2 pos = evt.position; and then changed the send message line as: to.SendMessage("FingerBegin",pos,SendMessageOptions.DontRequireReceiver); My other script should receive the message with: void FingerBegin ( Vector2 pos) { print(pos); } But when it runs, I get a: MissingMethodException: The best match for method FingerBegin has some invalid parameter error every time I touch using Unity Remote. Whaaaaaa...:( Any tips? Oooh why oh why does multi-touch have to be so complicated? Peter
– anon56119378Still waiting for an answer from some kind gentle sir or madame.
– anon56119378it sounds like you may have this script somewhere else as it is sending FingerBegin the touch evt, and this version which sends FingerBegin a Vector2. In any case you can leave the original code intact and have another game object get the message with touch evt, then simply access the position from the evt with evt.position...
– loopyllama