- Home /
Changing variable numbers depending on current player model.
Hello
For my game at the moment the player can switch between two models when pressing 1 or 2. I am trying to change the speed and jump speed depending on which model is selected. Can anyone help me out to where I should place the code? I've tried placing code into the if statements for 1 and 2 presses but the variables still don't change.
To switch models:
if (Input.GetKeyDown ("1")) { modelOne.SetActiveRecursively(true); modelTwo.SetActiveRecursively(false);
} else if (Input.GetKeyDown ("2")) { modelOne.SetActiveRecursively(false); modelTwo.SetActiveRecursively(true);
}
For the movement I am using:
private var moveDirection : Vector3 = Vector3.zero;
function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) {
moveDirection = Vector3(0, 0, Input.GetAxis("Horizontal")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;
print("Speed: " +speed); //Speed check
if(Input.GetKey ("left shift")) { jumpSpeed = 10.0; speed = 6.0; } else { speed = 4.0; jumpSpeed = 7.0; }
Thanks for any time taken to help!
Your answer
Follow this Question
Related Questions
Changing player model with keypress. 3 Answers
how do I set a variable to the key im pressing 2 Answers
Boolean not switching? 2 Answers
Changing character model in game 1 Answer
switching between in game characters 2 Answers