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 neph_2 · Sep 01, 2013 at 05:08 PM · inputjoysticknavigationmousepositionmultitouch

Input.mouseposition is confused by multiple clicks

I made virtual joystick for space game. I also have button to fire lasers. When used by 1 finger everything is ok, fire fires lasers and joystick drags and drop by mouse down and up that guide spaceship in space. The problem is when i put 2 fingers on screen of mobile together, the position is in the middle that cause problems that joystick is sticking to this middle position instead of finger intentionaly used to control joystick. The input i use is Input.mousePosition.

I also experimented with Input.GetTouch(0).deltaPosition and Input.GetTouch(0).position but none of them reacted on finger put on screen. (maybe i did something wrong)

void Update () { print(Input.touchCount); if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { print ("click position "+Input.GetTouch(0).deltaPosition); } }

If anyone could help me what can i do to make this task to work i would be very thankfull.

Comment
Add comment · Show 3
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 neph_2 · Sep 01, 2013 at 08:55 PM 0
Share

i am trying this on Samsung Galaxy S4

The thing is that something is maybe not configured (It dont work and i dont know why) When i print touchcount like this in sample script in C#

 public class Test : $$anonymous$$onoBehaviour {
 //...
     void Update () {
         print(Input.touchCount);
     }
 }

It print just "0" ,on each frame , even when i am touching the screen with fingers on mobile, and not even mouse click triggers increase of touchcount. How is this possible?

This code is linked on $$anonymous$$ainCamera and when i put some other code its normally working (i tryed to make new and clear project to test this = same result)

Any tip would help me a lot, cause i am stuck :( thanks for any help

avatar image fherbst neph_2 · Sep 01, 2013 at 08:56 PM 0
Share

Please edit your original question or make a comment ins$$anonymous$$d of wrongly posting an answer.

avatar image fherbst · Sep 01, 2013 at 09:02 PM 0
Share

Are you trying this via Unity Remote? Because that probably won't work, you have to test on the physical device.

1 Reply

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

Answer by fherbst · Sep 01, 2013 at 05:50 PM

If you want to use multiple fingers, use something like

 foreach(Touch t in Input.touches)
 {
   // check if touch t fullfills some conditions (e.g. is over joystick) and process it
 }

or

 for(int i = 0; i < Input.touchCount; i++)
 {
   Touch t = Input.GetTouch(i);
   // check if touch t fullfills some conditions (e.g. is over joystick) and process it
 }

GetTouch(0) will always just give you the first touch obviously. Your code looks fine otherwise, maybe you made a mistake somewhere else - what's your platform you're running this on?

EDIT: To check whether the system supports touch, use Input.multiTouchEnabled.

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 neph_2 · Sep 02, 2013 at 06:55 PM 0
Share

It was my mistake , i thought that mouseclick triggers touchCount

And btw the solution is that I check whather am I using pc or tablet/smartphone like platform on touch event(i dont know if this is ok but its first working way i found for both testing on pc and on smartphone)

 if (Input.touchCount == 0) {
     if (Input.Get$$anonymous$$ouseButtonDown(0) {
         //code for mouse - PC
     }
 } else {
     foreach(Touch newTouch in Input.touches) {
        //code for touchscreen
     }
 }

Thanks very much for your help and time, all the best.

avatar image meat5000 ♦ neph_2 · Sep 02, 2013 at 06:59 PM 0
Share

For platform dependant code follow the link

http://docs.unity3d.com/Documentation/$$anonymous$$anual/PlatformDependentCompilation.html

avatar image fherbst · Sep 02, 2013 at 06:57 PM 0
Share

Good, sounds like it's working now. Please accept an answer to help others as well.

avatar image fherbst · Sep 02, 2013 at 07:01 PM 0
Share

meat5000: that's also ok in principle, but since mul$$anonymous$$ch is not a "platform feature" but a general feature, I'd suggest using Input.multiTouchEnabled (feature dependant vs. platform dependant).

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I get the Vector2 from an input action in code? (New Input System) 1 Answer

How to get input from wheel(car direction) joystick? 1 Answer

Is there a way to create a floating JoyStick using the On-Screen Stick component? 0 Answers

How can I control cursor with joystick 4 Answers

Joystick Zone + Screen-swipe touch input clash. Solution??? 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