質問編集履歴

1

具体的にコードを追加した

2020/08/13 20:08

投稿

sh0824
sh0824

スコア7

test CHANGED
File without changes
test CHANGED
@@ -1,7 +1,183 @@
1
1
  現在unityでゲームを作成しています。
2
-
3
- そこで質問です。
4
2
 
5
3
  sliderを使用してタップしたらゲージを増やしたいのですが、どのようにすれば良いかわかりません。
6
4
 
7
5
  教えていただけたら嬉しいです。
6
+
7
+ またこのコードで実行すると、Assets/tapbutton.cs(47,9): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statementとエラーが出ます。
8
+
9
+
10
+
11
+
12
+
13
+ ```c#
14
+
15
+ using System.Collections;
16
+
17
+ using System.Collections.Generic;
18
+
19
+ using UnityEngine;
20
+
21
+ using UnityEngine.UI;
22
+
23
+
24
+
25
+ public class tapbutton : MonoBehaviour
26
+
27
+ {
28
+
29
+
30
+
31
+
32
+
33
+ // ボタンを定義
34
+
35
+ public Button BookButton;
36
+
37
+ // テキストエリアを定義
38
+
39
+ public Text countbook;
40
+
41
+ //カウンター数を記録
42
+
43
+ public int CountNum;
44
+
45
+
46
+
47
+ GameObject gameobject;
48
+
49
+
50
+
51
+ // Use this for initialization
52
+
53
+ void Start()
54
+
55
+ {
56
+
57
+
58
+
59
+
60
+
61
+ countbook.text = "0";
62
+
63
+ CountNum = 0;
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+ BookButton.onClick.AddListener(bookOnClick); //本を押したときに呼ばれるメソッドを指定
72
+
73
+
74
+
75
+
76
+
77
+ }
78
+
79
+
80
+
81
+ // Update is called once per frame
82
+
83
+ void Update()
84
+
85
+ {
86
+
87
+
88
+
89
+ }
90
+
91
+
92
+
93
+ // ボタンが押されたときに呼ばれるメソッド
94
+
95
+ void bookOnClick()
96
+
97
+ {
98
+
99
+ CountNum++; // カウンター変数を加算
100
+
101
+ TextAreaUpdate(CountNum);
102
+
103
+
104
+
105
+ GameObject director = GameObject.Find("GameDirector");
106
+
107
+ director.GetComponent<GameDirector>().IncreaseTap;
108
+
109
+
110
+
111
+ }
112
+
113
+
114
+
115
+ // テキストエリアの文字をアップデートするメソッド
116
+
117
+ void TextAreaUpdate(int num)
118
+
119
+ {
120
+
121
+ countbook.text = CountNum.ToString();
122
+
123
+ }
124
+
125
+
126
+
127
+ }
128
+
129
+ ```
130
+
131
+
132
+
133
+ ``` c#
134
+
135
+ using System.Collections;
136
+
137
+ using System.Collections.Generic;
138
+
139
+ using UnityEngine;
140
+
141
+ using UnityEngine.UI;
142
+
143
+
144
+
145
+ public class GameDirector : MonoBehaviour
146
+
147
+ {
148
+
149
+ Slider HpGauge;
150
+
151
+
152
+
153
+ // Start is called before the first frame update
154
+
155
+ void Start()
156
+
157
+ {
158
+
159
+
160
+
161
+ HpGauge = GameObject.Find("sinSlider").GetComponent<Slider>();
162
+
163
+
164
+
165
+ }
166
+
167
+
168
+
169
+ public void IncreaseTap()
170
+
171
+ {
172
+
173
+ HpGauge.value += 1;
174
+
175
+ }
176
+
177
+
178
+
179
+ }
180
+
181
+
182
+
183
+ ```