Mobile 团结在不同的高度跳跃
我正在为移动设备制作一个2D平台游戏。我有一把吉他,按下它,我的精灵就会跳起来。但每当我按下吉他,精灵每次都会跳到不同的高度,这取决于我是按住按钮还是轻轻按下按钮 以下是我正在使用的跳转脚本:Mobile 团结在不同的高度跳跃,mobile,unity3d,unity3d-2dtools,Mobile,Unity3d,Unity3d 2dtools,我正在为移动设备制作一个2D平台游戏。我有一把吉他,按下它,我的精灵就会跳起来。但每当我按下吉他,精灵每次都会跳到不同的高度,这取决于我是按住按钮还是轻轻按下按钮 以下是我正在使用的跳转脚本: using UnityEngine; using System.Collections; public class Jump : MonoBehaviour { public GUITexture jumpButton; bool grounded = false;
using UnityEngine;
using System.Collections;
public class Jump : MonoBehaviour {
public GUITexture jumpButton;
bool grounded = false;
public Transform groundCheck;
float groundRadius = 0.2f;
public LayerMask whatIsGround;
public float jumpForce = 700f;
public GameObject character;
void Start () {
}
void Update () {
}
void FixedUpdate () {
grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
if (grounded && jumpButton.HitTest(Input.GetTouch(0).position)) {
rigidbody2D.AddForce(new Vector2(0, jumpForce));
}
}
}
让你的if语句检查触地阶段如果触地是向下的,那么它只会在你触地时触发一次
if (grounded && jumpButton.HitTest(Input.GetTouch(0).position) && Input.GetTouch(0).phase == TouchPhase.Began) {
rigidbody2D.AddForce(new Vector2(0, jumpForce));
}