teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

回答追記

2015/07/06 07:52

投稿

wakuwaku
wakuwaku

スコア386

answer CHANGED
@@ -24,4 +24,86 @@
24
24
 
25
25
  }
26
26
  ```
27
- それとも1回のUpdate(最初の1フレーム目)でHPが0になるまでダメージを与え続けたいということですか?
27
+ それとも1回のUpdate(最初の1フレーム目)でHPが0になるまでダメージを与え続けたいということですか?
28
+
29
+
30
+ 追記
31
+ サンプルだけは示しますが、プログラムを書く上で自分で調べることがとても大事です。
32
+ 「○○はどうやりますか。」という質問ではなく、「○○をこれだけ調べてみたのですが、△△のところがどうしてもわかりません。□□であっていますか?」というような質問ができるように心がけるといいですよ。
33
+
34
+ ```lang-C#
35
+ using UnityEngine;
36
+ using System.Collections;
37
+ //オーディオ再生
38
+ public class VS : MonoBehaviour {
39
+
40
+
41
+ public AudioSource audiosource;
42
+ public AudioSource audiosource2;
43
+
44
+ private DragonStatus status;
45
+ private DeathStatus status2;
46
+
47
+ public AudioClip audioclip;
48
+ public AudioClip audioclip2;
49
+
50
+
51
+ // 以下をメンバ変数として宣言
52
+ int DragonMAXHP = 0;
53
+ int DeathMAXHP = 0;
54
+
55
+ int DragonReceivedamage = 0;
56
+ int DeathReceivedamage = 0;
57
+
58
+ int DragonleftHP = 0;
59
+ int DeathleftHP = 0;
60
+
61
+
62
+ void Start () {
63
+ audiosource = gameObject.GetComponent<AudioSource> ();
64
+ audiosource.clip = audioclip;
65
+ audiosource.Play ();
66
+
67
+
68
+ status = GetComponent<DragonStatus> ();
69
+ status2 = GetComponent<DeathStatus> ();
70
+
71
+ DragonMAXHP = status.HP;
72
+ DeathMAXHP = status2.HP;
73
+
74
+ DragonReceivedamage = status2.attack - status.defend;
75
+ DeathReceivedamage = status.attack - status2.defend;
76
+
77
+
78
+ DragonleftHP = DragonMAXHP -= DragonReceivedamage;
79
+ DeathleftHP = DeathMAXHP -= DeathReceivedamage;
80
+ }
81
+
82
+
83
+
84
+ void Update(){
85
+
86
+ // なんかifの中身が違う気がしたので直しました。
87
+ // おせっかいでしたら戻してください。
88
+ Debug.Log (DragonMAXHP);
89
+ if(Input.GetMouseButtonDown(0))
90
+ {
91
+ DragonMAXHP -= DragonReceivedamage;
92
+ }
93
+ Debug.Log (DeathMAXHP);
94
+
95
+ audio.PlayOneShot(audioclip);
96
+ if(Input.GetMouseButtonDown(0))
97
+ {
98
+ DeathMAXHP -= DeathReceivedamage;
99
+ }
100
+ audio.PlayOneShot(audioclip2);
101
+
102
+ if(DragonMAXHP < 0 || DeathMAXHP < 0)
103
+ {
104
+ // DragonMAXHPまたはDeathMAXHPのどちらかが0になった時の処理
105
+ }
106
+
107
+ }
108
+ }
109
+ ```