-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterAnimation.cs
59 lines (52 loc) · 2.34 KB
/
CharacterAnimation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
* CharacterAnimation is an animation template class
* Checks the state of player and plays corrsponding animation
*/
public static class CharacterAnimation{
/*
* See if a target character is touching the ground or not
*/
public static bool GroundDetecting(Rigidbody rb) {
float ground_distance = 3f; // distance between player and the ground.
LayerMask Ground = LayerMask.NameToLayer("Ground"); // objects in ground are in "Ground" layer.
return (Physics.Raycast(rb.transform.position, Vector3.down, ground_distance, Ground) && (rb.velocity.y <= 0.2f));
//will return true if character is only 3 unit away from the ground
//this is because landing animation must play few seconds before the character touches the ground
}
/*Actual animate method*/
public static void Animate(bool movingornot, Animator anim, Rigidbody rb, bool grounded, bool isAttacking, bool isDead)
{
anim.SetBool("isRunning", movingornot);
anim.SetBool("isGrounded", GroundDetecting(rb) || grounded); // True if (3 unit away from the ground OR actually touching the ground)
anim.SetBool("isAttacking", isAttacking);
anim.SetBool("isDead", isDead);
}
}
/*
* Class specifically designed for player
*/
public static class PlayerAnimation {
public static void Animate(bool movingornot, Animator anim, Rigidbody rb, bool grounded, bool weapon, bool isDead) {
CharacterAnimation.Animate(movingornot, anim, rb, grounded, weapon, isDead);
}
}
/*
* Class specifically designed for enemy(with gun)
*/
public static class EnemyAnimation {
public static void Animate(bool movingornot, Animator anim, Rigidbody rb, bool grounded, bool isAttacking, bool isDead) {
CharacterAnimation.Animate(movingornot, anim, rb, grounded, isAttacking, isDead);
}
}
/*
* Class specifically designed for enemy(melee)
*/
public static class EnemyMeleeAnimation {
public static void Animate(bool movingornot, Animator anim, Rigidbody rb, bool grounded, bool isAttacking, bool isDead, int attacktype) {
CharacterAnimation.Animate(movingornot, anim, rb, grounded, isAttacking, isDead);
anim.SetInteger("attacktype", attacktype);
}
}