How to convert space bar key event in unity into touch event in android?

GB Golden
  using UnityEngine;
  public class Player : MonoBehaviour
    {
        // The force which is added when the player jumps
        // This can be changed in the Inspector window
        public Vector2 jumpForce = new Vector2(0, 300);
        // Update is called once per frame
            void Update ()
            {
                // Jump`enter code here
                if (Input.GetKeyUp("space")) /*This is written for spacebar event so how can make it a touch event and to use in it android project */
                {
                    GetComponent<Rigidbody2D>().velocity = Vector2.zero; GetComponent<Rigidbody2D>().AddForce(jumpForce);//It all works fine
                }
            }
        }
Programmer

If you are looking for a simple press anywhere on the screen, this should do it.

if (Input.GetMouseButtonDown(0))
{
   GetComponent<Rigidbody2D>().velocity = Vector2.zero; 
   GetComponent<Rigidbody2D>().AddForce(jumpForce);
}

OR

if ((Input.touchCount > 0) && (Input.GetTouch(0).phase == TouchPhase.Began))
{
   GetComponent<Rigidbody2D>().velocity = Vector2.zero; 
   GetComponent<Rigidbody2D>().AddForce(jumpForce);
}

If you are looking for Button UI on the screen, learn the Unity UI System.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to programmatically trigger the touch event in android?

From Dev

How to make the touch event in openstreetmap android

From Dev

How to stop touch event for desired time in android?

From Dev

How to programmatically trigger the touch event in android?

From Dev

How to stop touch event for desired time in android?

From Dev

Android inject touch event

From Dev

Android: Send a touch event

From Dev

Android inject touch event

From Dev

Android: Send a touch event

From Dev

Unity3D Convert Key Event to plain text

From Dev

How to add a key event handler that listens for the Space key?

From Dev

Android move view on touch event

From Dev

Android - "Faking" a touch event not working

From Dev

Touch or Click event ViewPagerIndicator in Android

From Dev

Android - "Faking" a touch event not working

From Dev

Android service listen to touch event

From Dev

Android Studio : ListView On Touch Event

From Dev

How to get touch event / tap event on GMSPanoramaView

From Dev

How to make Enter key the same as the Space Bar key - Android

From Dev

How to find if ACTION_MOVE touch event is on a circular path: Android

From Dev

how to intercept every touch event on whole android screen?

From Dev

How to check if a touch event is outside or inside of a region in android

From Dev

how to do different event on first and second touch (TicTacToe for Android)

From Dev

How to check if a touch event is outside or inside of a region in android

From Dev

LibGdx, How to handle touch event?

From Dev

how to add name for touch event

From Dev

Android - Send touch event to other views

From Dev

Handle touch event for items inside Recyclerview - android

From Dev

Android Nested ViewPager Disable Touch Event

Related Related

  1. 1

    How to programmatically trigger the touch event in android?

  2. 2

    How to make the touch event in openstreetmap android

  3. 3

    How to stop touch event for desired time in android?

  4. 4

    How to programmatically trigger the touch event in android?

  5. 5

    How to stop touch event for desired time in android?

  6. 6

    Android inject touch event

  7. 7

    Android: Send a touch event

  8. 8

    Android inject touch event

  9. 9

    Android: Send a touch event

  10. 10

    Unity3D Convert Key Event to plain text

  11. 11

    How to add a key event handler that listens for the Space key?

  12. 12

    Android move view on touch event

  13. 13

    Android - "Faking" a touch event not working

  14. 14

    Touch or Click event ViewPagerIndicator in Android

  15. 15

    Android - "Faking" a touch event not working

  16. 16

    Android service listen to touch event

  17. 17

    Android Studio : ListView On Touch Event

  18. 18

    How to get touch event / tap event on GMSPanoramaView

  19. 19

    How to make Enter key the same as the Space Bar key - Android

  20. 20

    How to find if ACTION_MOVE touch event is on a circular path: Android

  21. 21

    how to intercept every touch event on whole android screen?

  22. 22

    How to check if a touch event is outside or inside of a region in android

  23. 23

    how to do different event on first and second touch (TicTacToe for Android)

  24. 24

    How to check if a touch event is outside or inside of a region in android

  25. 25

    LibGdx, How to handle touch event?

  26. 26

    how to add name for touch event

  27. 27

    Android - Send touch event to other views

  28. 28

    Handle touch event for items inside Recyclerview - android

  29. 29

    Android Nested ViewPager Disable Touch Event

HotTag

Archive