質問編集履歴

2

修正

2020/09/20 04:02

投稿

dedede914
dedede914

スコア63

test CHANGED
File without changes
test CHANGED
@@ -58,22 +58,30 @@
58
58
 
59
59
 
60
60
 
61
+   Update()
62
+
63
+ {Punch();} //エラー
64
+
65
+
66
+
61
67
    void Punch()
62
68
 
63
69
  {
64
70
 
65
- playermanager playermanager = new playermanager();
66
-
67
- punch1 punch1 = GetComponent<punch1>(); //普通にインスタンス化したらnullが出たので何となくこうしました
68
-
69
- punch2 punch2 = GetComponent<punch2>();
70
-
71
- punch3 punch3 = GetComponent<punch3>();
72
-
73
71
  if (Input.GetKeyDown(KeyCode.Space))
74
72
 
75
73
  {
76
74
 
75
+ playermanager playermanager = new playermanager();
76
+
77
+ punch1 punch1 = GetComponent<punch1>(); //普通にインスタンス化したらnullが出たので何となくこうしました
78
+
79
+ punch2 punch2 = GetComponent<punch2>();
80
+
81
+ punch3 punch3 = GetComponent<punch3>();
82
+
83
+
84
+
77
85
  animator.SetTrigger("attack");
78
86
 
79
87
  UnityEngine.Debug.Log(playermanager.getpunchnum());
@@ -86,7 +94,7 @@
86
94
 
87
95
  case 0:
88
96
 
89
- punch1.Punch();
97
+ punch1.Punch(); 
90
98
 
91
99
  break;
92
100
 

1

詳細追加

2020/09/20 04:01

投稿

dedede914
dedede914

スコア63

test CHANGED
File without changes
test CHANGED
@@ -30,13 +30,137 @@
30
30
 
31
31
  ### 該当のソースコード
32
32
 
33
-
34
-
35
33
  ```C#
36
34
 
35
+ //追加1個目
36
+
37
+ public class playermanager : MonoBehaviour
38
+
39
+ {
40
+
41
+ public static int punchnum;
42
+
43
+   public void setpunchnum()
44
+
45
+ { playermanager.punchnum += 1;}
46
+
47
+
48
+
49
+ public int getpunchnum()
50
+
51
+ { return playermanager.punchnum ; }
52
+
53
+
54
+
55
+ public void resetpunchnum()
56
+
57
+ {playermanager.punchnum = 0;}
58
+
59
+
60
+
61
+   void Punch()
62
+
63
+ {
64
+
65
+ playermanager playermanager = new playermanager();
66
+
67
+ punch1 punch1 = GetComponent<punch1>(); //普通にインスタンス化したらnullが出たので何となくこうしました
68
+
69
+ punch2 punch2 = GetComponent<punch2>();
70
+
71
+ punch3 punch3 = GetComponent<punch3>();
72
+
73
+ if (Input.GetKeyDown(KeyCode.Space))
74
+
75
+ {
76
+
77
+ animator.SetTrigger("attack");
78
+
79
+ UnityEngine.Debug.Log(playermanager.getpunchnum());
80
+
81
+ switch (playermanager.getpunchnum())
82
+
83
+ {
84
+
85
+
86
+
87
+ case 0:
88
+
89
+ punch1.Punch();
90
+
91
+ break;
92
+
93
+ case 1:
94
+
95
+ punch2.Punch();
96
+
97
+ break;
98
+
99
+ case 2:
100
+
101
+ punch3.Punch();
102
+
103
+ break;
104
+
105
+ }
106
+
107
+ playermanager.setpunchnum();
108
+
109
+ if (playermanager.getpunchnum() >= 3) playermanager.resetpunchnum();
110
+
111
+ }
112
+
113
+ }
114
+
115
+ }
116
+
117
+ ```
118
+
119
+ ```C#
120
+
121
+ //追加2個目
122
+
123
+ //punch2とpunch3もあります
124
+
125
+ public class punch1 : MonoBehaviour
126
+
127
+ {
128
+
129
+ public Transform punchtyu;
130
+
131
+ public GameObject punchtyufab;
132
+
133
+ public Transform appearpoint;
134
+
135
+ public GameObject appearpointprefab;
136
+
137
+
138
+
139
+ public void Punch()
140
+
141
+ {
142
+
143
+ Instantiate(punchtyufab, punchtyu.position, transform.rotation);
144
+
145
+ Instantiate(appearpointprefab, appearpoint.position, transform.rotation);
146
+
147
+ }
148
+
149
+ }
150
+
151
+
152
+
153
+ ```
154
+
155
+
156
+
157
+ ```C#
158
+
159
+ //こちらはいったん忘れていただいて
160
+
37
161
  //Punch1()と同じように2,3もあります
38
162
 
39
- void Punch1()
163
+ void Punch()
40
164
 
41
165
  {
42
166