没有脚本错误 - 字符不跳 - Unity 3d

时间:2014-05-09 23:53:31

标签: unity3d unityscript

目前正在构建一个2D游戏,并为我的角色Ezio'创建了一个javascript代码。但是当我按下“空间”时,它什么也没做。它跳。代码也没有错误。

#pragma strict
var jump :float = 0; 
var jumpspeed : float = 15; 
var jumptimer :float = 0; 
function Start () {
}
function Update () {
    if (jump == 1) {
        jumptimer = jumptimer +1;
        if (jumptimer >= 50) {
            jumptimer = 0;
            jump = 0;
        }
    }
}
if (Input.GetKeyDown ("space"))
{
    if (jump == 0) {
        rigidbody2D.velocity.y = jumpspeed;
        jump = 1;
    }
}

关于可能出现什么问题的任何建议?

1 个答案:

答案 0 :(得分:2)

试试这个:

#pragma strict
var jump :float = 0; 
var jumpspeed : float = 15; 
var jumptimer :float = 0; 
function Start () {
}


function Update() {

    if (Input.GetKeyDown("space")) {

        if (jump == 1) {
            jumptimer = jumptimer + 1;
            if (jumptimer >= 50) {
                jumptimer = 0;
                jump = 0;
            }
        } else {
            rigidbody2D.velocity.y = jumpspeed;
            jump = 1;
        }
    }

}