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 S_Byrnes · Mar 11, 2014 at 04:03 AM · androidinputtouchmultiplekeycode

Touch Inputs Not Allowing Mutiple Presses

Hey guys, I've been trying to sort this problem out for a couple of days now, I had help from FifthKnotch about a similar problem 2 days ago, since then I've got my code nearly working fine on mobile, the user can do everything I want them to do, but they can't do any of them at the same time.

         count = Input.touchCount;
     foreach ( Touch touch in Input.touches) {
         if (moveUp.HitTest(touch.position)) {
             {
                 //Move Up
             }
             
         }
         else
         {
             //Stop Animations & Sound
         }
         
         if (moveLeft.HitTest(touch.position)) {
             //Spin Left
         }
         if (moveRight.HitTest(touch.position)) {
             //Spin Right
         }
     }
     
    if (Input.GetKey(KeyCode.Space)&&Time.time>nextShotTime)
    {
      nextShotTime = Time.time+fireInterval;
      if (GameObject.FindWithTag("Player"))
      {
       GameObject go = GameObject.FindWithTag("Player");
       Vector3 newPos = new Vector3(-0.3f,0.0f,0.0f);
       newPos = go.transform.TransformPoint(newPos);

       GameObject projectile = Instantiate(Shot, go.transform.position, go.transform.rotation) as GameObject;
       Physics.IgnoreCollision(projectile.collider, go.collider);
       Rigidbody rb = (Rigidbody)projectile.GetComponent("Rigidbody");
       rb.velocity = go.transform.TransformDirection(Vector3.left) * 10;
      }
    }

I hope that's not too much code for you, I removed the actual code's after the IF statements because I don't feel they're relevant, but if you need them, just ask. I left in the shoot code at the bottom because that one is having the most bugs

I did get the fire button to work on mobile devices using a similar code to the rest, but I couldn't figure out how to do a Time.time>nextShotTime with the touch input

TLDR: I need to have all of my touch inputs able to work with each-other and I need to work out how to shoot in the parameters of nextShotTime

Thank you in advanced for anyone who can help me, I'm pretty desperate!

Comment
Add comment
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

1 Reply

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

Answer by fifthknotch · Mar 11, 2014 at 04:33 AM

Hello again. The reason your script is not multi-touch is because you are using the same variable "touch" for every button. Touch can ONLY have one value at a given time. Because of this, the first touch is assigned for all buttons. If you make separate scripts all with a touch variable for checking if your touch is on their assigned button, this should solve your problem.

Comment
Add comment · Show 13 · 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 S_Byrnes · Mar 11, 2014 at 04:37 AM 0
Share

Huh.. ok thanks, how exactly would that look? And would that still work to control the same object if it was all in different scripts?

avatar image fifthknotch · Mar 11, 2014 at 04:45 AM 0
Share

Split these:

 if (moveUp.HitTest(touch.position)) {
          {
          //$$anonymous$$ove Up
          }
      
       }
       else
       {
         //Stop Animations & Sound
 }

and

 if (moveLeft.HitTest(touch.position)) {
           //Spin Left
        }

and

 if (moveRight.HitTest(touch.position)) {
          //Spin Right
        }

and so on, into individual scripts, each checking its own touch input. That way it can change as more fingers are added.

avatar image S_Byrnes · Mar 11, 2014 at 04:49 AM 0
Share

Alright I'll give that a go, just to clarify though, I have this code above each individual script:

        count = Input.touchCount;
     foreach ( Touch touch in Input.touches) {

And then do I link it to the prefab of my ship or the button itself?

avatar image fifthknotch · Mar 11, 2014 at 04:56 AM 0
Share

Yes. $$anonymous$$eep that so your scripts keep up with the touch inputs. $$anonymous$$eep these scripts on the same object you had them on.

avatar image S_Byrnes · Mar 11, 2014 at 05:00 AM 0
Share

Alright cheers, I'll let you know how I go

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

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

Touch buttons to replace Input GetKey KeyCode 1 Answer

Input.GetAxis("Vertical") on touch devices. 2 Answers

Touch Input help.. 1 Answer

TouchPhase not firing correctly - Android 3 Answers

How to touch a specific cube 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