3rd person controller

i understand that many people using the script to control only one animation file which they separated into 3 parts by keyframes.(idle, walk and run)

However i did the three animations in 3 separate files...i do not know how to control these three files together by the script and make the 3rd person controller..

really thanks for the help:D

You are partially correct. Although, many people don't use 1 animation file and jump around in it, Unity let's you split that file so that there are actually 3 animation files (idle, walk, run.) Making 3 separate files, I assume you mean using the character@animation method, will give you the same number of animation files as the other method. To control them through scripting, you use the exact same method for both.

function Update () {
    if(Input.GetAxis("Vertical") > .1) {
         if(Input.GetButton("Fire1")) {
              animation.CrossFade("yourRunAnimationName");
         }

         else {
              animation.CrossFade("yourWalkAnimationName");
         }
    }

    else {
         animation.CrossFade("yourIdleAnimationName");
    }
}

P.S. This method is extremely basic, and is just meant to give you an example. You probably want to write your own for your actual script.

this is my script.. -i cant switch between the animations by using the xxx@xxx method and it only generate walking cycle..but can only rotate..

private var walkSpeed : float = 1.0; private var gravity = 100.0; private var moveDirection : Vector3 = Vector3.zero; private var charController : CharacterController; //private var power : float = 4.0;

function Start() { charController = GetComponent(CharacterController); animation.wrapMode = wrapMode.Loop; }

function Update () { if(charController.isGrounded == true) { if(Input.GetAxis("Vertical") > .1) {

         animation["walk"].speed = 1;
         animation.CrossFade("walk");
         walkSpeed = 6;

        if(Input.GetButton("run")  )
        {

            animation.CrossFade("run");
            walkSpeed = 10;
        }
        else
        {

            animation["walk"].speed = 1;
            animation.CrossFade("walk");
            walkSpeed = 6;
        }  

    }
    else if(Input.GetAxis("Vertical") < -.1)
    {

        animation["walk"].speed = -1;
        animation.CrossFade("walk");
        walkSpeed = 6;
    }
    else if(Input.GetButton("jump")  )
        {
            animation["jump"].speed = 1;
            animation.CrossFade("jump");
            walkSpeed = 6;
        }
    // Create an animation cycle for when the character is turning on the spot
    if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical"))
    {
        Debug.Log ("horizontal n not get axis vertical");
        //animation.CrossFade("walk");
    }

    Debug.Log("turning...");

    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));

}

this is my movement control script to switch the animations..

function Start() { animation.wrapMode = WrapMode.Loop; }

function FixedUpdate () { if(Input.GetAxis("Vertical") > .1) {

        if(Input.GetButton("run")  )
        {

            animation.CrossFade("run");
            walkSpeed = 4;
        }
        else
        {

            animation["walk"].speed = 1;
            animation.CrossFade("walk");
            walkSpeed = 1;
        }  

    }
    else if(Input.GetAxis("Vertical") < -.1)
    {

        animation["walk"].speed = -1;
        animation.CrossFade("walk");
        walkSpeed = 1;
    }
    else if(Input.GetButton("jump")  )
    {
            animation["jump"].speed = 1;
            animation.CrossFade("jump");
            walkSpeed = 4;
    }
    // Create an animation cycle for when the character is turning on the spot

}