モバイル デバイス用の 2D プラットフォーム ゲームを作成しています。押すとスプライトがジャンプするguiTextureがあります。しかし、guiTexture を押すたびに、ボタンを押したままにするか軽く押すかによって、スプライトが毎回異なる高さでジャンプします。
私が使用しているジャンプスクリプトは次のとおりです。
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));
}
}
}