我无法配置角色跳跃的高度。 (团结2d)

时间:2014-11-30 02:24:56

标签: unity3d unityscript

我从教程中得到了一个脚本,当你按下按钮时我的播放器会跳转,但我不知道如何配置跳跃的高度。下面是代码:

var before : Sprite;
var after : Sprite;
var isGrounded : boolean;
var Animator : Animator;
var character : GameObject;
var jump : float = 0;
var jumpSpeed : float = 5;
var jumpTimer : float = 0;

function Start () {
    isGrounded = true;  
}

function Update () {
    Animator.SetBool("isGrounded", isGrounded);
    if(jump == 1) {
        jumpTimer = jumpTimer + 1;
    }
    if(jumpTimer >= 50) {
        jumpTimer = 0;
        jump = 0;
    } 
}

function OnMouseDown () {
    isGrounded = false;
    GetComponent(SpriteRenderer).sprite = after;
    if(jump == 0) {
        character.GetComponent(Rigidbody2D).velocity.y = jumpSpeed;
        jump = 1;
    }
    yield WaitForSeconds (0.5);
    isGrounded = true;
}

function OnMouseUp () {
   GetComponent(SpriteRenderer).sprite = before;    
}

我尝试降低跳跃/跳跃/跳跃的浮子,但它只是不起作用。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

将我的评论放在使用相同教程并遇到相同问题的其他人的答案中。

以下线路用于改变球员的速度。

character.GetComponent(Rigidbody2D).velocity.y = jumpSpeed;

要更改播放器的跳跃高度,您需要更改jumpSpeed变量。

注意 如果要更改脚本顶部的jumpSpeed变量并且它没有更改,那是因为检查器中的值会覆盖脚本顶部输入的值。