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 Fred22 · Apr 03, 2015 at 12:25 AM · touchcursorcontrolareaidentify

How to identify touches via area

Hi, is there a way of storing a certain part of the touch area as a value, similar to FingerId, so that you can control, say 2 individual balls?

Also, is there a way of controlling the cursor, via a small touchpad, within a touch only game? Thanks!

Comment
Add comment · Show 2
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 KdRWaylander · Apr 03, 2015 at 07:05 AM 0
Share

I'm not quite sure to understand what you mean here, could you be more precise ? You can add a canvas and slipt it in two panels (children) that would always be fully transparent and then add an event system on it (it's a component) - a button ins$$anonymous$$d of the panel could work too, but i'm not sure that that's what you want ?

avatar image Fred22 · Apr 03, 2015 at 11:25 AM 0
Share

The problem is that doing that still doesn't allow me to control more than 2 axes no matter how many fingers I use, I'm looking for a way to isolate each or at least 2 finger's input in a way that they don't have to both be on at the same time, but that is relative to the position on screen. The idea being controlling separate objects that mirror each finger, but are not dragged. Thanks again.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ozturkcompany · Apr 03, 2015 at 11:49 AM

I might have been understood your question. OK, lets split out the screen to 2 parts vertically. I assume that you know how to use Input.touches array. You need to check the phase of your touch first and where the touch has been made(position on the screen). The first of a touch will always be touch phase began, so when a touch has been made and if it was in the left part of the screen, call that touch a name, something like touch_L. So you now know that there is a touch on the left parf of the screen. So do a if statament and say like, if touch_L.position.x < Screen.width/2(which means touch is on the left part of the screen) //Do some coding. I hope you understand the logic. Hope this helps out.

Comment
Add comment · Show 6 · 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 Fred22 · Apr 03, 2015 at 12:19 PM 0
Share

Right, it's just that I don't understand how to link an object's XY movement to an if statement, which is why I was hoping I could add something like touch_L to any object I wanted and it would only read that. Once I find the object, how do I declare I want to update it's position relative to my left hand finger, most likely at varying proportion?

if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.$$anonymous$$oved)

{touchDelta = Input.GetTouch(0).deltaPosition;}

This is what I had before, and trying to split the screen just moved both objects simultaneously.

avatar image ozturkcompany · Apr 03, 2015 at 12:33 PM 0
Share
 #pragma strict
 private var TouchID : int = -1;
 
 function Update ()
 {
     if(Input.touchCount > 0)
     {
         for(var touch : Touch in Input.touches)
         {
             if(touch.phase == TouchPhase.Began)
             {
                 TouchID = touch.fingerId;
             }
             if(touch.phase != TouchPhase.Ended && touch.fingerId == TouchID)
             {
                 if(touch.position.x < Screen.width/2)//Touches are on the left side of the screen
                 {
                     //Do something
                 }
                 if(touch.position.x > Screen.width/2)//Touches are on the right side of the screen
                 {
                     //Do something
                 }
             }
             if(touch.phase == TouchPhase.Ended)
             {
                 TouchID = -1;
             }
         }
     }
 }

Hope this works! Please guru's check the script that i've written above as it might have some problems. Cheers

avatar image Fred22 · Apr 03, 2015 at 12:41 PM 0
Share

Never wrote in java before, but I've been looking for an excuse to start anyway, so yeah thanks a lot!

avatar image KdRWaylander · Apr 03, 2015 at 01:29 PM 2
Share

C# translation from @ozturkcompany:

     using UnityEngine;
 using System.Collections;
 
 public class Container$$anonymous$$anager : $$anonymous$$onoBehaviour
 {
     private int TouchID = -1;
     
     void Update ()
     {
         if(Input.touchCount > 0)
         {
             for(Touch touch in Input.touches)
             {
                 if(touch.phase == TouchPhase.Began)
                 {
                     TouchID = touch.fingerId;
                 }
                 if(touch.phase != TouchPhase.Ended && touch.fingerId == TouchID)
                 {
                     if(touch.position.x < Screen.width/2)//Touches are on the left side of the screen
                     {
                         //Do something
                     }
                     if(touch.position.x > Screen.width/2)//Touches are on the right side of the screen
                     {
                         //Do something
                     }
                 }
                 if(touch.phase == TouchPhase.Ended)
                 {
                     TouchID = -1;
                 }
             }
         }
     }
 }
avatar image Fred22 · Apr 03, 2015 at 02:30 PM 1
Share

Sweet, never expected such helpfulness, and of course I over-thought the issue, didn't stop it from consu$$anonymous$$g me though!

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

Adding Touch Controls to Car Game 1 Answer

Editable text field in Android with cursor 0 Answers

I have my touch controls configured but they don't move across the entire background 0 Answers

iOS :: increase slider thumb touch area 1 Answer


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