C#unity双跳编码用于玩家移动控制 使用UnityEngine; 使用系统集合; 公共类玩家运动:单一行为 { 公共浮子速度=3.0f; 公共浮子跳跃速度=200.0f; 公共布尔值=真; 公共浮动时间=4.0f; //用于初始化 无效开始() { } //每帧调用一次更新 无效固定更新() { Vector3 x=Input.GetAxis(“水平”)*transform.right*Time.deltaTime*速度; 如果(时间
这应该可以做到:C#unity双跳编码用于玩家移动控制 使用UnityEngine; 使用系统集合; 公共类玩家运动:单一行为 { 公共浮子速度=3.0f; 公共浮子跳跃速度=200.0f; 公共布尔值=真; 公共浮动时间=4.0f; //用于初始化 无效开始() { } //每帧调用一次更新 无效固定更新() { Vector3 x=Input.GetAxis(“水平”)*transform.right*Time.deltaTime*速度; 如果(时间,c#,unity3d,dynamic,C#,Unity3d,Dynamic,这应该可以做到: 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 =
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");
}
}
你对这段代码很在行,我测试了一下,效果很好,但我发现在自由落体时,玩家仍然接受dblJump命令,我不希望这样。有没有办法解决这个问题,在一定的加速度范围内,dblJump是活动的,一旦像自由落体一样越过该加速度范围,dblJump选项就被禁用。你可以试试d检查rigidbody.velocity()这应该代表你的下降速度
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");
}