Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Katie.Fisher555 · Sep 26, 2015 at 05:52 PM · inputtouch controlstouch screen

How to enable multiple button presses on a touchscreen virtual button control scheme

I am trying to develop a basic mobile game, and am having a little bit of a problem with the controls.

my initial keyboard-controlled code worked very smoothly and allowed the player to move along the x axis and shoot simultaneously. Left and right arrow keys moved, spacebar shoot.

 void Update () {
     myTransform.Translate(Vector3.right * playerSpeed * Input.GetAxis("Horizontal") * Time.deltaTime);
     
    
  if (Input.GetKeyDown (KeyCode.Space)) {
     
                 Vector3 position = new Vector3(myTransform.position.x, myTransform.position.y + 1, myTransform.position.z);
                 
                 Instantiate(laser, position, Quaternion.identity);
 }

However, since moving to a mobile interface i've drawn virtual buttons on the screen and used those to control the player.

 void OnGUI() {
 
         if (GUI.Button (new Rect (425, 900, 200, 200), SpaceshipFire)) {
             Vector3 position = new Vector3 (myTransform.position.x, myTransform.position.y + 1, myTransform.position.z);
             //fire laser
             Instantiate (laser, position, Quaternion.identity);
         }
         if (GUI.RepeatButton (new Rect (200, 900, 200, 200), SpaceshipRight)) {
 
             myTransform.Translate (Vector3.right * playerSpeed * Time.deltaTime);
         }
         if (GUI.RepeatButton (new Rect (0, 900, 200, 200), SpaceshipLeft)) {
 
             myTransform.Translate (Vector3.left * playerSpeed * Time.deltaTime);
         }

The problem is:

Say you want to move left continuously while shooting. You would expect to hold the "Move Left" button down while tapping the "Shoot" button. In my old code, that was fine. In the new code, pressing the "shoot" button overrides you pressing the "move left" button. You cannot move and shoot.

I think I need to be looking at multitouch stuff, but all my searches lead to implementing multitouch gestures (like pinch to zoom).

Would just like to know where to look really.

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
1

Answer by Rostam24 · Sep 26, 2015 at 08:30 PM

I use UI Buttons in my game, this would work for you as well. Then in each UI Button, add a script that implements IPointerDownHandler to see if the button has been pressed, and build the player controls from there.

Comment
Add comment · Show 1 · 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 habibieamrullah · Oct 09, 2017 at 01:27 PM 0
Share

your answer is not helpful....

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Help In Making a SphereCast for 3D Tire! Working RayCast Script included! 0 Answers

How can we make touch controls like Hole.io/ Bumper.io? 0 Answers

When pressing a button, it counts as pressing the screen and the button [New Input System] 0 Answers

Using right version of .Net-Framework with Unity 5.2.3f1 in context of TUIO protocol and MS PixelSense-Table 0 Answers

Convert Input Mouse in Input touch and test Unity 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