我从一个教程中得到了一个脚本,当你按下一个按钮时,它会让我的播放器跳起来,但我不知道如何配置它跳得多高。代码如下:
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;
}我试着降低跳跃/跳转速度/跳跃计时器的浮点数,但就是不起作用。有什么想法吗?
发布于 2014-11-30 15:13:11
将我的评论放在一个答案中,供任何其他使用相同教程并有相同问题的人使用。
下面这条线用来改变玩家的速度。
character.GetComponent(Rigidbody2D).velocity.y = jumpSpeed;为了更改播放器的跳跃高度,您需要更改jumpSpeed变量。
注意如果您正在更改脚本顶部的jumpSpeed变量,并且该变量没有更改,这是因为检查器中的值覆盖了在脚本顶部输入的值。
https://stackoverflow.com/questions/27209360
复制相似问题