-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeCakeSM.cs
103 lines (88 loc) · 2.75 KB
/
MakeCakeSM.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
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
103
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class MakeCakeSM : AIState
{
Transform pancakeTarget;
float pettingrange = 0;
Vector3 pos =Vector3.zero;
public MakeCakeSM(NavMeshAgent ag, FiniStateMachine st, KitchenHelper hp, STATUS _status, stateType stateTYPE, Animator an) : base(ag, st, hp, _status, stateTYPE, an)
{
helper.onReciveMaterial += OnReciveMaterial;
pettingrange = status.pettingrange;
}
bool waiting;
float waitingTime = 3;
float waitCounter = 3;
//タワーとの距離のチェック
void makeCAKE()
{
float distance = Vector3.Distance(helper.transform.position, helper.towerScript.transform.position);
if (distance <= pettingrange)
{
if (agent.destination != agent.transform.position)
moveTo(helper.transform.position);
anim.SetTrigger(StaticStrings.petting);
helper.haveMaterial = false;
helper.towerScript.Build(helper.pancakeValue);
waiting = true;
}
}
public override void EnterState()
{
base.EnterState();
stateMachine.WeaponModel.SetActive(false);
}
//マテリアルを貰って、タワーへ移動
public void OnReciveMaterial()
{
anim.SetTrigger(StaticStrings.pickUp);
moveTo(helper.towerScript.transform.position);
}
//material を集りにいく
public void goToTakeMaterial()
{
float d = float.MaxValue;
foreach (Transform t in PancakeSpawner.instance.pancakes)
{
if (t == null) continue;
pos = new Vector3(t.position.x, helper.transform.position.y, t.position.z);
float distanc = Vector3.Distance(helper.transform.position, pos);
if (distanc < d)
{
d = distanc;
pancakeTarget = t;
}
}
if (pancakeTarget == null) { return; }
moveTo(pos);
}
public override void UPDATING()
{
if (waiting)
{
moveTo(helper.transform.position);
waitCounter -= Time.deltaTime;
if (waitCounter <= 0)
{
waitCounter = waitingTime;
waiting = false;
}
return;
}
if (helper.haveMaterial)
{
makeCAKE();
}
else
{
goToTakeMaterial();
}
}
public override void ExitState()
{
base.ExitState();
helper.haveMaterial = false;
}
}