Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by peter · Mar 30, 2011 at 12:58 PM · multitouch

Finger Manager position

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[i];
            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[i];
            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);
                  }
               }
               fingers[i] = fingers[fingers.Count-1];
               fingers.RemoveAt(fingers.Count-1);
            }
            else {
               ++i;
            }
         }
      }
   }

} }

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Justin Warner · Mar 30, 2011 at 01:59 PM 1
Share

Next time you post code, please use the 10101 button up top to format it correctly =). Thanks a lot!

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by loopyllama · Mar 30, 2011 at 03:28 PM

evt is your Touch, so evt.position is your touch position, which is a vector2 so something like:

Vector2 pos = evt.position;

just send pos in a message with SendMessage which is documented with an example here: http://unity3d.com/support/documentation/ScriptReference/GameObject.SendMessage.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image peter · Mar 30, 2011 at 05:53 PM 0
Share

@ Harmless Ahhh, Thank You.

@JW, Will do, where is that button though?

avatar image peter · Apr 03, 2011 at 02:21 AM 0
Share

Hi there, I added Vector2 pos = evt.position; and then changed the send message line as: to.Send$$anonymous$$essage("FingerBegin",pos,Send$$anonymous$$essageOptions.DontRequireReceiver);

$$anonymous$$y other script should receive the message with: void FingerBegin ( Vector2 pos) { print(pos); } But when it runs, I get a: $$anonymous$$issing$$anonymous$$ethodException: 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

avatar image peter · Apr 22, 2011 at 08:28 PM 0
Share

Still waiting for an answer from some kind gentle sir or madame.

avatar image loopyllama · Apr 23, 2011 at 08:46 AM 0
Share

it 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...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

C# script for unity camera. Detect difference between two finger swipe and pinch to zoom? 2 Answers

Problem in Disabling Multi touch 0 Answers

MultiTouch issues 1 Answer

Go from mouse to multitouch? 1 Answer

Windows 10 multitouch test in editor 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges