質問編集履歴
2
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -28,21 +28,25 @@
|
|
28
28
|
public void resetpunchnum()
|
29
29
|
{playermanager.punchnum = 0;}
|
30
30
|
|
31
|
+
Update()
|
32
|
+
{Punch();} //エラー
|
33
|
+
|
31
34
|
void Punch()
|
32
35
|
{
|
33
|
-
playermanager playermanager = new playermanager();
|
34
|
-
punch1 punch1 = GetComponent<punch1>(); //普通にインスタンス化したらnullが出たので何となくこうしました
|
35
|
-
punch2 punch2 = GetComponent<punch2>();
|
36
|
-
punch3 punch3 = GetComponent<punch3>();
|
37
36
|
if (Input.GetKeyDown(KeyCode.Space))
|
38
37
|
{
|
38
|
+
playermanager playermanager = new playermanager();
|
39
|
+
punch1 punch1 = GetComponent<punch1>(); //普通にインスタンス化したらnullが出たので何となくこうしました
|
40
|
+
punch2 punch2 = GetComponent<punch2>();
|
41
|
+
punch3 punch3 = GetComponent<punch3>();
|
42
|
+
|
39
43
|
animator.SetTrigger("attack");
|
40
44
|
UnityEngine.Debug.Log(playermanager.getpunchnum());
|
41
45
|
switch (playermanager.getpunchnum())
|
42
46
|
{
|
43
47
|
|
44
48
|
case 0:
|
45
|
-
punch1.Punch();
|
49
|
+
punch1.Punch();
|
46
50
|
break;
|
47
51
|
case 1:
|
48
52
|
punch2.Punch();
|
1
詳細追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,10 +14,72 @@
|
|
14
14
|
```
|
15
15
|
|
16
16
|
### 該当のソースコード
|
17
|
+
```C#
|
18
|
+
//追加1個目
|
19
|
+
public class playermanager : MonoBehaviour
|
20
|
+
{
|
21
|
+
public static int punchnum;
|
22
|
+
public void setpunchnum()
|
23
|
+
{ playermanager.punchnum += 1;}
|
17
24
|
|
25
|
+
public int getpunchnum()
|
26
|
+
{ return playermanager.punchnum ; }
|
27
|
+
|
28
|
+
public void resetpunchnum()
|
29
|
+
{playermanager.punchnum = 0;}
|
30
|
+
|
31
|
+
void Punch()
|
32
|
+
{
|
33
|
+
playermanager playermanager = new playermanager();
|
34
|
+
punch1 punch1 = GetComponent<punch1>(); //普通にインスタンス化したらnullが出たので何となくこうしました
|
35
|
+
punch2 punch2 = GetComponent<punch2>();
|
36
|
+
punch3 punch3 = GetComponent<punch3>();
|
37
|
+
if (Input.GetKeyDown(KeyCode.Space))
|
38
|
+
{
|
39
|
+
animator.SetTrigger("attack");
|
40
|
+
UnityEngine.Debug.Log(playermanager.getpunchnum());
|
41
|
+
switch (playermanager.getpunchnum())
|
42
|
+
{
|
43
|
+
|
44
|
+
case 0:
|
45
|
+
punch1.Punch();
|
46
|
+
break;
|
47
|
+
case 1:
|
48
|
+
punch2.Punch();
|
49
|
+
break;
|
50
|
+
case 2:
|
51
|
+
punch3.Punch();
|
52
|
+
break;
|
53
|
+
}
|
54
|
+
playermanager.setpunchnum();
|
55
|
+
if (playermanager.getpunchnum() >= 3) playermanager.resetpunchnum();
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
```
|
18
60
|
```C#
|
61
|
+
//追加2個目
|
62
|
+
//punch2とpunch3もあります
|
63
|
+
public class punch1 : MonoBehaviour
|
64
|
+
{
|
65
|
+
public Transform punchtyu;
|
66
|
+
public GameObject punchtyufab;
|
67
|
+
public Transform appearpoint;
|
68
|
+
public GameObject appearpointprefab;
|
69
|
+
|
70
|
+
public void Punch()
|
71
|
+
{
|
72
|
+
Instantiate(punchtyufab, punchtyu.position, transform.rotation);
|
73
|
+
Instantiate(appearpointprefab, appearpoint.position, transform.rotation);
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
```C#
|
80
|
+
//こちらはいったん忘れていただいて
|
19
81
|
//Punch1()と同じように2,3もあります
|
20
|
-
void
|
82
|
+
void Punch()
|
21
83
|
{
|
22
84
|
playermanager playermanager = new playermanager(); {
|
23
85
|
if (Input.GetKeyDown(KeyCode.Space)){
|