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
}
}
}
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.
Comments