2014-09-22 6 views
0

모바일 장치 용 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)); 
     } 
    } 
} 

답변

0

touchphase에 대한 문 검사는 터치 다운되면 경우

if (grounded && jumpButton.HitTest(Input.GetTouch(0).position) && Input.GetTouch(0).phase == TouchPhase.Began) { 
     rigidbody2D.AddForce(new Vector2(0, jumpForce)); 
    } 
을 터치하면, 그때는 한 번만 발생됩니다 만들