Using the Unity’s Animation System

  • Create an Animator Controller, name it DarrenController
  • Select the DarrenController Animator, double click and drag the Idle animation onto it
  • Select the Darren_3D gameobject in hierarchy, Add an Animator Component and in the Controller slot select the DarrenController.
  • Add the Walk and Throw animations into the controller
  • Make transitions between Idle and Walk with right click on the animation
  • Uncheck the HasExitTimeoption in the transitions

Switching between animations

  • In the Animator tab, create a new parameter of type bool and call it Walk
  • Select the Idle-Walk transition, Add a new condition Walk as true
  • For Walk-Idle transition, choose Walk as false
  • In the Player script, create and link a variable to reference the Animator component in children
  • Set the Walk value to true when click on left mouse button
public Animator animator;
void Start(){
animator = GetComponentInChildren<Animator>();
}
void Update(){
if (Input.GetMouseButtonDown(0)){
if (Physics.Raycast(rayOrigin, out hitInfo)){
animator.SetBool("Walk",true);
}}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store