[英]What is wrong with my c# player jumping code ? (unity 3d)
I just started learning unity 3d, and I wrote c# code that makes my player jump but it is not working我刚开始学习统一 3d,我写了 c# 代码让我的播放器跳起来但它不起作用
public Rigidbody rb;
public float SideWaysForce = 500f;
bool CanJump;
void OnCollisionEnter(Collision collisioninfo)
{
if (collisioninfo.collider.tag == "Ground")
{
Debug.Log("Can Jump");
CanJump = true;
}
if (collisioninfo.collider.tag != "Ground")
{
Debug.Log("Can not Jump");
CanJump = false;
}
}
void FixedUpdate()
if (CanJump == true && Input.GetKey("space"))
{
rb.AddForce(0, SideWaysForce * Time.deltaTime, 0);
}
no error messages were shown in the Console控制台中未显示任何错误消息
Well, debug (with a debugger or with Debug.Log
) if the script even works, then make sure both CanJump
and Input.GetKey("Space")
are true.好吧,调试(使用调试器或使用
Debug.Log
)如果脚本甚至可以工作,那么请确保CanJump
和Input.GetKey("Space")
都为真。 Also, you probably should use Input.GetKeyDown
if you don't want your character to fly when you're holding a key.此外,如果您不想让角色在握着钥匙时飞起来,您可能应该使用
Input.GetKeyDown
。
Input.GetKey("Space")
not Input.GetKey("space")
(I believe the capital letter matters).Input.GetKey("Space")
而不是Input.GetKey("space")
(我相信大写字母很重要)。 If non of these solutions fix your issue please tell me.如果这些解决方案都不能解决您的问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.