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
}
}
}
答案 0 :(得分:1)
如果您正在寻找屏幕上任何地方的简单按,那就应该这样做。
C:\opts\Python27>pip install requests
Collecting requests
Could not find a version that satisfies the requirement requests (from versions: )
No matching distribution found for requests
OR
if (Input.GetMouseButtonDown(0))
{
GetComponent<Rigidbody2D>().velocity = Vector2.zero;
GetComponent<Rigidbody2D>().AddForce(jumpForce);
}
如果您正在寻找屏幕上的Button UI,learn Unity UI系统。