Hi am i am trying to make my char run when shift held down… it works fine if i remove the jump part but … It’s like i can’t have more then 2 if statements at same time. cus then the third don’t work . Is there some max ? tryed changing and make it an else but no luck.
var speed = 6.0;
var walkSpeed = 6;
var jumpSpeed = 8.0;
var gravity = 20.0;
var runSpeed = 15;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
// lots of vars not every one is in in use atm, but should not matter
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
// i am jumping (problem from here to )
if (Input.GetKeyDown (KeyCode.Space)) {
print("jump");
moveDirection.y = jumpSpeed;
// i am running
if(Input.GetKey(KeyCode.LeftShift)){
moveDirection *= runSpeed;
print ("You are running mfo");
// (problem end)
}
}
}
// 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)