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 gugu6897 · Jan 09, 2013 at 01:13 PM · guitouchmultitoucharea

Multitouch Area

I'm brazilian and my english is basic.

I have two types of input on my game (racing game):

•Vertical input (Two button that move forward and backward);

•Horizontal input (Horizontal slider that rotates the car);

But if I press the Slider and the Button, the touch does not work properly.

How can I create a "multitouch area", like those "touch areas" in FPS game, in which the left part of screen moves the player, and the right part of the screen moves the aim camera.

Part of my code:

 //Vertical Input        
         if (Input.GetMouseButton(0) && GUI.RepeatButton( Rect( Screen.width -  Screen.width/10, Screen.height - Screen.width /5, Screen.width /12, Screen.width /12 ), cima))
         {
             VerticalGUI = 1;
         }
         else if (Input.GetMouseButton(0) && GUI.RepeatButton( Rect( Screen.width - Screen.width/10, Screen.height - Screen.width /10, Screen.width /12, Screen.width /12 ), baixo))
         {
             GUI.RepeatButton( Rect( Screen.width - Screen.width/10, Screen.height - Screen.width /5, Screen.width /12, Screen.width /12 ), cima);
             VerticalGUI = -1;
         }
         else
         {
         VerticalGUI = 0;
         }
 //Horizontal Input
     if (Input.GetMouseButton(0))
     {
         HoriGUI = GUI.HorizontalSlider (Rect (Screen.width /25, Screen.height - Screen.height /10, Screen.width /3.8, Screen.height /16), HoriAll, -30.0, 30.0);
     }
     else
         HoriGUI = GUI.HorizontalSlider (Rect (Screen.width /25, Screen.height - Screen.height /10, Screen.width /3.8, Screen.height /16), 0, -30.0, 30.0);
 
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 AlucardJay · Jan 09, 2013 at 01:16 PM 0
Share

This is a collection of the comments I posted on this question : http://answers.unity3d.com/questions/373516/brother-in-arms-style-joystick-and-fire-button.html

Normally you check for touches within certain rectangles on the screen. If there is a touch on the left, use that touch in move calculations; if there is a touch on the right, use that touch for firing calculations.

avatar image gugu6897 · Jan 27, 2013 at 02:37 PM 0
Share

I'm just searching a solution to make a GUI compatible with different mul$$anonymous$$ch areas. But now I know that GUI does not have support to $$anonymous$$ul$$anonymous$$ch.

I'm looking for an Android game, not for iOS devices.

1 Reply

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

Answer by AlucardJay · Jan 09, 2013 at 01:17 PM

To expand on my first comment, what normally happens is first you define rectangles that represent areas on the screen :

 // set control input zones - joystick on left, fire button on right
 joystickRect = new Rect(0, 0, Screen.width * 0.5, Screen.height * 1.0);
 fireBtnRect = new Rect(Screen.width * 0.5, 0, Screen.width, Screen.height * 1.0);

then when you get your touch input, check if it is in one of the areas :

 if ( joystickRect.Contains( touch.position ) ) 
 {
     // do joystick stuff
 } 
 else if ( fireBtnRect.Contains( touch.position ) )  
 {
     // do firing stuff
 }

This is the script I learned from : http://wiki.unity3d.com/index.php/Tap_to_Move_Drag_to_Look_iPhone

What to have first is some kind of input manager :

 // TOUCH
 var count : int = Input.touchCount;
 
 for (var i : int = 0;  i < count;  i++)
 {  
     var touch : Touch = Input.GetTouch (i);
    
     if (touch.phase == TouchPhase.Began)
         OnTouchBegan(touch.fingerId, touch.position);
     else if (touch.phase == TouchPhase.Moved)
         OnTouchMoved(touch.fingerId, touch.position);
     else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
         OnTouchEnded(touch.fingerId);
     else if (touch.phase == TouchPhase.Stationary)
         OnTouchStationary(touch.fingerId);
 }


that passes the touch input to one of 4 functions. :

 // -- Control Functions -- 
 
 function OnTouchBegan(fingerId : int, pos : Vector2)
 function OnTouchEnded(fingerId : int)
 function OnTouchMoved(fingerId : int, pos : Vector2)
 function OnTouchStationary(fingerId : int)


In OnTouchBegan, first it checks what area of the screen (rect) the touch started in, and stores a reference to that finger ID :

 function OnTouchBegan(fingerId : int, pos : Vector2)
 {
     if (leftFingerId == -1 && joystickRect.Contains(pos)) 
     {
         leftFingerId = fingerId;
         leftFingerStartPoint = leftFingerCurrentPoint = pos;
     } 
     else if (rightFingerId == -1 && fireBtnRect.Contains(pos))  
     {
         rightFingerStartPoint = rightFingerCurrentPoint = pos;
     }
 }
 

OnTouchEnded checks which fingerID has been ended, and removes the reference to that finger :

 function OnTouchEnded(fingerId : int)
 {
     if (fingerId == leftFingerId)
     {
         leftFingerId = -1;
         
         // reset Joystick vars
         leftFingerCurrentPoint = leftFingerStartPoint;
         joystickOffset = Vector2.zero;
         playerInput = Vector2.zero;
     }        
     else if (fingerId == rightFingerId)
     {
         rightFingerId = -1;
     }   
            
 }
 

OnTouchMoved checks the finger ID, and calculates the change in position since the last frame :

 function OnTouchMoved(fingerId : int, pos : Vector2)
 {
     if (fingerId == leftFingerId)
         leftFingerCurrentPoint = pos;
     else if (fingerId == rightFingerId)
     {
         rightFingerCurrentPoint = pos;
         firingTimer += Time.deltaTime;
     }
 }
    

That is just the basics, and this is alot of information to absorb!

Comment
Add comment · Show 3 · 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 AlucardJay · Jan 12, 2013 at 09:24 AM 0
Share

This is alot of information, do you see what is happening to check if a touch is only in a certain area (Rect)?

avatar image gugu6897 · Jan 27, 2013 at 02:21 PM 0
Share

Sorry, but I can't use this answer with GUI.

avatar image AlucardJay · Jan 27, 2013 at 02:28 PM 0
Share

But the question is $$anonymous$$ul$$anonymous$$ch Area , not take inputs from GUI. And this is how $$anonymous$$ul$$anonymous$$ch Areas are done. Normally your GUI elements are rendered afterwards in positions based on the calculations as advised above, look at any iOS input script. Also I'm fairly sure Unitys GUI doesn't work on iOS, that's why you need to use something like NGUI or UIToolkit. Perhaps you should be looking at NGUI : http://u3d.as/content/tasharen-entertainment/ngui-next-gen-ui/2vh

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

9 People are following this question.

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

Related Questions

How to identify touches via area 1 Answer

Issues with using multitouch and event trigger on 2 joysticks 1 Answer

Touch ID ????? 1 Answer

How to display Swipe Marks on iPhone 1 Answer

Multi Touch Disable on Virtual Joy-pad (FPS) 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