回答編集履歴

1

回答追記

2015/07/06 07:52

投稿

wakuwaku
wakuwaku

スコア386

test CHANGED
@@ -51,3 +51,167 @@
51
51
  ```
52
52
 
53
53
  それとも1回のUpdate(最初の1フレーム目)でHPが0になるまでダメージを与え続けたいということですか?
54
+
55
+
56
+
57
+
58
+
59
+ 追記
60
+
61
+ サンプルだけは示しますが、プログラムを書く上で自分で調べることがとても大事です。
62
+
63
+ 「○○はどうやりますか。」という質問ではなく、「○○をこれだけ調べてみたのですが、△△のところがどうしてもわかりません。□□であっていますか?」というような質問ができるように心がけるといいですよ。
64
+
65
+
66
+
67
+ ```lang-C#
68
+
69
+ using UnityEngine;
70
+
71
+ using System.Collections;
72
+
73
+ //オーディオ再生
74
+
75
+ public class VS : MonoBehaviour {
76
+
77
+
78
+
79
+
80
+
81
+ public AudioSource audiosource;
82
+
83
+ public AudioSource audiosource2;
84
+
85
+
86
+
87
+ private DragonStatus status;
88
+
89
+ private DeathStatus status2;
90
+
91
+
92
+
93
+ public AudioClip audioclip;
94
+
95
+ public AudioClip audioclip2;
96
+
97
+
98
+
99
+
100
+
101
+ // 以下をメンバ変数として宣言
102
+
103
+ int DragonMAXHP = 0;
104
+
105
+ int DeathMAXHP = 0;
106
+
107
+
108
+
109
+ int DragonReceivedamage = 0;
110
+
111
+ int DeathReceivedamage = 0;
112
+
113
+
114
+
115
+ int DragonleftHP = 0;
116
+
117
+ int DeathleftHP = 0;
118
+
119
+
120
+
121
+
122
+
123
+ void Start () {
124
+
125
+ audiosource = gameObject.GetComponent<AudioSource> ();
126
+
127
+ audiosource.clip = audioclip;
128
+
129
+ audiosource.Play ();
130
+
131
+
132
+
133
+
134
+
135
+ status = GetComponent<DragonStatus> ();
136
+
137
+ status2 = GetComponent<DeathStatus> ();
138
+
139
+
140
+
141
+ DragonMAXHP = status.HP;
142
+
143
+ DeathMAXHP = status2.HP;
144
+
145
+
146
+
147
+ DragonReceivedamage = status2.attack - status.defend;
148
+
149
+ DeathReceivedamage = status.attack - status2.defend;
150
+
151
+
152
+
153
+
154
+
155
+ DragonleftHP = DragonMAXHP -= DragonReceivedamage;
156
+
157
+ DeathleftHP = DeathMAXHP -= DeathReceivedamage;
158
+
159
+ }
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+ void Update(){
168
+
169
+
170
+
171
+ // なんかifの中身が違う気がしたので直しました。
172
+
173
+ // おせっかいでしたら戻してください。
174
+
175
+ Debug.Log (DragonMAXHP);
176
+
177
+ if(Input.GetMouseButtonDown(0))
178
+
179
+ {
180
+
181
+ DragonMAXHP -= DragonReceivedamage;
182
+
183
+ }
184
+
185
+ Debug.Log (DeathMAXHP);
186
+
187
+
188
+
189
+ audio.PlayOneShot(audioclip);
190
+
191
+ if(Input.GetMouseButtonDown(0))
192
+
193
+ {
194
+
195
+ DeathMAXHP -= DeathReceivedamage;
196
+
197
+ }
198
+
199
+ audio.PlayOneShot(audioclip2);
200
+
201
+
202
+
203
+ if(DragonMAXHP < 0 || DeathMAXHP < 0)
204
+
205
+ {
206
+
207
+ // DragonMAXHPまたはDeathMAXHPのどちらかが0になった時の処理
208
+
209
+ }
210
+
211
+
212
+
213
+ }
214
+
215
+ }
216
+
217
+ ```