我对 Unity 4.0.0 有疑问。当我玩 AngryBots 项目时,甚至当我使用简单的行走脚本制作自己的 char 时,它会自动行走而无需按任何按钮。
我尝试卸载 Unity,我尝试使用旧版本的 Unity,我什至将其从注册表中删除,但我仍然得到相同的行为。为什么会这样?这是一个错误,还是我做错了什么?
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
} // Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
我将这个脚本用于我所有的行走字符并且它可以工作,但现在它会自动行走。