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");
}
}应该在哪里,什么类型的编码可以让它在回到地面之前跳两次?
有一个物体上面有精灵纸,我已经获得了基于物理引擎的约束运动和正常跳跃的统一。但我希望运动更有活力,只在没有接地的情况下跳两次,并在一定的时间范围内跳跃两次,就像在地面休息时在几毫秒间隔内按下跳跃按钮来重置位置一样。
发布于 2013-09-25 18:45:12
这应该能起到作用:
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");
}https://stackoverflow.com/questions/19002590
复制相似问题