回答編集履歴
1
スクリプトを追記
answer
CHANGED
@@ -4,4 +4,56 @@
|
|
4
4
|
|
5
5
|
現在どのアニメーションが再生されているか(どのステートにいるか)は
|
6
6
|
`anim.GetCurrentAnimatorStateInfo(0).IsName("State名")`
|
7
|
-
がtrueかfalseかで判断できます。
|
7
|
+
がtrueかfalseかで判断できます。
|
8
|
+
|
9
|
+
コルーチンでコンボを繋げるなら例えばこんな感じです。
|
10
|
+
```c#
|
11
|
+
using System.Collections;
|
12
|
+
using System.Collections.Generic;
|
13
|
+
using UnityEngine;
|
14
|
+
|
15
|
+
public class Teratail : MonoBehaviour
|
16
|
+
{
|
17
|
+
static readonly int NumCombo = 2;//最大コンボ数
|
18
|
+
Animator animator;
|
19
|
+
bool isAttack = false;//攻撃中かどうか
|
20
|
+
|
21
|
+
void Start()
|
22
|
+
{
|
23
|
+
animator = GetComponent<Animator>();
|
24
|
+
}
|
25
|
+
|
26
|
+
void Update()
|
27
|
+
{
|
28
|
+
if (Input.GetKeyDown(KeyCode.Z) && !isAttack)//攻撃中でないときにZキーが押された
|
29
|
+
{
|
30
|
+
StartCoroutine(Combo());//コンボスタート
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
IEnumerator Combo()
|
35
|
+
{
|
36
|
+
isAttack = true;
|
37
|
+
|
38
|
+
bool nextCombo = true;//コンボが繋がるかどうか
|
39
|
+
for (int i = 1; nextCombo && i <= NumCombo; i++)
|
40
|
+
{
|
41
|
+
nextCombo = false;
|
42
|
+
animator.SetTrigger("NextCombo");//i番目のコンボ開始
|
43
|
+
yield return new WaitForSeconds(0.1f);
|
44
|
+
while (animator.GetCurrentAnimatorStateInfo(0).normalizedTime < 1f)//コンボiの間
|
45
|
+
{
|
46
|
+
if (Input.GetKeyDown(KeyCode.Z)) nextCombo = true;//キーが押されたらコンボが繋がる
|
47
|
+
yield return null;
|
48
|
+
}
|
49
|
+
yield return new WaitForSeconds(0.3f);//次の攻撃は0.3秒後
|
50
|
+
}
|
51
|
+
|
52
|
+
animator.SetTrigger("EndCombo");
|
53
|
+
isAttack = false;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
```
|
57
|
+
|
58
|
+
アニメーターはこうなります。
|
59
|
+

|