Rabbit.cs
1.89 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum RabbitState
{
None,
Pop,
Idle,
Die,
Exit
}
public class Rabbit : MonoBehaviour
{
private Animator m_animator;
public RabbitState state = RabbitState.None;
public GameObject body;
private float m_resetTime = 0f;
private float m_exitTime = 0f;
private void Awake()
{
m_animator = GetComponent<Animator>();
SetResetTime();
}
private void SetResetTime()
{
m_resetTime = Random.Range(1.5f, 6f);
}
public void None()
{
state = RabbitState.None;
body.SetActive(false);
m_animator.SetBool("dying", false);
m_animator.SetBool("exiting", false);
SetResetTime();
}
public void Pop()
{
state = RabbitState.Pop;
body.SetActive(true);
m_animator.SetBool("poping", true);
}
public void Idle()
{
state = RabbitState.Idle;
m_animator.SetBool("poping", false);
}
public void Die()
{
state = RabbitState.Die;
m_animator.SetBool("dying", true);
}
public void Exit()
{
state = RabbitState.Exit;
m_exitTime = 0f;
m_animator.SetBool("exiting", true);
}
private void Update()
{
if (MiniGameManager.gameState == GameState.Play)
{
float dt = Time.deltaTime;
if (state == RabbitState.None)
{
body.SetActive(false);
m_resetTime -= dt;
if (m_resetTime <= 0)
Pop();
return;
}
else if (state == RabbitState.Idle)
{
m_exitTime += dt;
if (m_exitTime >= 2)
Exit();
return;
}
}
else
return;
}
}