触地时跳跃

时间:2018-01-07 18:40:53

标签: c# unity3d

触摸屏幕后,我有一个球体跳跃。在我之前的代码中,它跳了无限的时间,但在当前的代码中,它只跳了一次。我希望每次触摸屏幕时球体都会跳跃,但主要问题是,我希望它只在地面上跳时才能跳跃。我试过这个......

public float speed;
public Rigidbody rb;
private bool thrown ;



void Start() 
{
    rb = GetComponent<Rigidbody>();
}

void Update() 
{
    if (
        !thrown && (
            (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended ) ||
            Input.GetMouseButtonDown(0) )
    )
    {
        rb.isKinematic = false;
        rb.AddForce (new Vector3(0.0f, 0.5f, 0.2f));
        thrown = true ;

    }
}
void OnTriggerEnter(Collider other)
{ 
    if (other.gameObject.CompareTag ("player")) 
    {
        thrown = true;
    }
}

我认为我在ontriggerEnter上做错了,或者可能在其他地方。请帮帮我。

0 个答案:

没有答案