0
using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour 
{
public float speed          = 3.0f;
public float jumpSpeed          = 200.0f;
public bool grounded            = true;
public float time           = 4.0f;     



// Use this for initialization
void Start () 
{

}

// Update is called once per frame
void FixedUpdate () 
{
    Vector3 x = Input.GetAxis("Horizontal")* transform.right * Time.deltaTime *      speed;

    if (time <= 2)
    {
    if(Input.GetButtonDown("Jump"))
        {
                Jump();
        }

    }

    transform.Translate(x);

    //Restrict Rotation upon jumping of player object
    transform.rotation = Quaternion.LookRotation(Vector3.forward);


}
void Jump()
    {
        if (grounded == true)
        {
            rigidbody.AddForce(Vector3.up* jumpSpeed);


            grounded = false;
        }

    }
void OnCollisionEnter (Collision hit)
{
    grounded = true;
    // check message upon collition for functionality working of code.
    Debug.Log ("I am colliding with something");
}

}

应该在哪里以及什么类型的编码可以让它在回到地面之前跳跃两次?

有一个带有精灵表的对象,我已经获得了基于物理引擎的统一约束运动和正常跳跃。但我希望运动更具动态性,并且只有在未接地时以及在特定时间范围内进行两次跳跃,例如在静止在地面上时重置位置之前在几毫秒间隔内按下跳跃按钮时。

4

1 回答 1

0

这应该可以解决问题:

private bool dblJump = true;

void Jump()
{
    if (grounded == true)
    {
        rigidbody.AddForce(Vector3.up* jumpSpeed);

        grounded = false;
    } 
    else if (!grounded && dblJump)
    {
        rigidbody.AddForce(Vector3.up* jumpSpeed);

        dblJump = false;
    }

}

void OnCollisionEnter (Collision hit)
{
    grounded = true;
    dblJump = true;
    // check message upon collition for functionality working of code.
    Debug.Log ("I am colliding with something");
}
于 2013-09-25T10:45:11.810 回答