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
1
Question by Bennyboy50z · May 18, 2014 at 10:02 PM · multitouchtouchesraycasts

From Input.GetMouse to Input.touch. Multi-touch and raycasts?

Hi Guys. So I'm trying to figure out how to use Input.Touch. Usually I use Input.GetMouseButton(0) and draw a raycast to where ever the person touched on the screen.

Now what I'm trying to do is make it so the player can touch multiple buttons at once. The arrows buttons and any other button the same time. I want it so you can press anything in Box 1 as well anything from the other Box 2s at the same time. I've tried looking at similar answers but am quite confused about how to work multi-touch controls.

So I think what I need is to draw separate raycasts from separate finger touches but I'm not really sure. I heard raycasts are quite expensive so this may not be the best option for mobile controls. Any help is appreciated and I'll attach the relevant code I have so far. The code below is used pretty much on both scripts but with different hit.collider.names.

Thanks in advance for any assistance!

alt text

 private var ray : Ray;
 private var hit : RaycastHit; 
 
 function Update()
 ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 Click1();
 }
 
 function Click1(){
         if(Input.GetMouseButton(0)){     
         if(Physics.Raycast(ray, hit,100f)){
     if (hit.collider.gameObject.name == "RightArrow"){ 
         //DoSomething
 }
 }
 }
 }
 



gscreenie.png (212.8 kB)
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 robertbu · May 19, 2014 at 12:28 AM 0
Share

Start with the sample scripts here:

https://docs.unity3d.com/Documentation/ScriptReference/Input.GetTouch.html

avatar image Bennyboy50z · May 19, 2014 at 01:16 AM 0
Share

Thanks the third example looks like what I need I'm just having a little bit of trouble making out how they work. I'm guessing if(Input.GetTouch(i).phase == TouchPhase.Began) is somewhat like (Input.Get$$anonymous$$ouseButton(0))? then perhaps I can change (i) between (0) and (1) for multiple touches?

avatar image Bennyboy50z · May 19, 2014 at 01:32 AM 0
Share

Actually I just found a tutorial that seems to be explaining the things I'm confused about. If anybody else is interested this has helped: http://forum.unity3d.com/threads/202940-Unity-Touch-Input-Tutorials

1 Reply

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

Answer by brzydal · May 19, 2014 at 01:26 AM

Hi, try this:

 function Update()
 {
     if(Input.touchCount > 0)
     {
         for(var i:int = 0; i<Input.touchCount; i++)
         {
             if(Input.touches[i].phase==TouchPhase.Ended)
             {
                 var ray:Ray = Camera.main.ScreenPointToRay(Input.touches[i].position);
                 var hit:RaycastHit;
                 if(Physics.Raycast(ray, hit, 100f))
                 {
                     Click(hit.collider.gameObject.name);
                 }
             }
         }
     }
 }
 
 function Click(name:String)
 {
     if(name.Equals("RightArrow"))
     {
         //DoSomething;
     }
     else if(name.Equals("SomethingElse"))
     {
         //DoSomethingElse
     }
 }
Comment
Add comment · Show 2 · 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 Bennyboy50z · May 19, 2014 at 02:48 AM 0
Share

I'll integrate it tomorrow and tell you how it works, I just looked at a few other sources and think I understand touch input a lot better now, thanks very much!

avatar image Bennyboy50z · May 19, 2014 at 05:13 PM 0
Share

Thanks this really helped!

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

21 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 avatar image avatar image avatar image

Related Questions

How to get multitouch input using EasyTouch 0 Answers

Unusual multitouch behavior (Android) 3 Answers

How to use multi touch 0 Answers

Finger Manager position 1 Answer

uniTUIO touch delay 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