private var walkSpeed : float = 1.0;
private var gravity = 100.0;
private var moveDirection : Vector3 = Vector3.zero;
private var charController : CharacterController;
var Camera1 = GameObject.Find("Camera1");
var Camera2 = GameObject.Find("Camera2");
function Start()
{
charController = GetComponent(CharacterController);
Camera2.enabled = true;
Camera1.enabled = false;
}
function Update ()
{
if(charController.isGrounded == true)
{
if(Input.GetAxis("Vertical") > .1)
{
walkSpeed = 2;
}
else if(Input.GetAxis("Vertical") < -.1)
{
walkSpeed = 1;
}
// Create an animation cycle for when the character is turning on the spot
transform.eulerAngles.y += Input.GetAxis("Horizontal");
// Calculate the movement direction (forward motion)
moveDirection = Vector3(0,0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
}
moveDirection.y -= gravity * Time.deltaTime;
charController.Move(moveDirection * (Time.deltaTime * walkSpeed));
if (Input.GetKeyDown ("2")){
Camera1.enabled = false;
Camera2.enabled = true;
}
if (Input.GetKeyDown ("1"))
{
Camera1.enabled = true;
Camera2.enabled = false;
}
}
please give me a suggestion?.I want to switch between two cameras