[Prototype 3] Set Up Animations
How to open Animator Window
- After you click on the Player, apply an Animator Component in your Inspector.
- Attach your file for Controller and Avatar and double-click on that Controller box.
- You can see that it actually opens up a brand new window in your Scene for Animators.
- If you want to move around in this view, you can use your mouse wheel.
How to set up a jump animation
I wanted to do somethings to the jumping animation to really make it look real.
So I opened my PlayerController Script, and got a reference to my Animator.
It’s really similar to how I got a reference to my Rigidbody.
PlayerController.cs
1
private Animator playerAnim;
Just like Rigidbody, I needed to get the actual Component on my Object.
1
2
3
4
void Start()
{
playerAnim = GetComponent<Animator>();
}
And I wanted to enter Update() function is actually where I wanted this animation to happen.
But I had no idea what animation exactly were I trying to make happen.
So I went to the Animator and found out player animator.
I went to my Jumping layer and typed the code in script.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private Animator playerAnim;
void Start()
{
...
playerAnim = GetComponent<Animator>();
...
}
void Update()
{
...
playerAnim.SetTrigger("Jump_trig");
}
How to set up a falling animation
I needed to add one more thing, which was whenever I collide with one of obstacles, I didn’t want to keep running into one of obstacles.
So I found from “Alive” to a “Death_01” in my Deaths Layer.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public bool gameOver = false;
private void ConCollisionEnter(Collision collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
isInGround = true;
} else if(collision.gameObject.CompareTag("Obstacle"))
{
Debug.Log("Game Over!")
gmaeOver = true;
playerAnim.SetBool("Death_b", true);
playerAnim.SetInteger("DeathType_int", 1);
}
}