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

質問編集履歴

2

書式を改善いたしました。よろしくお願い致します。

2021/08/31 08:00

投稿

kutigaiinioi-_-
kutigaiinioi-_-

スコア4

title CHANGED
File without changes
body CHANGED
@@ -121,34 +121,36 @@
121
121
  ```
122
122
 
123
123
  【スコアを管理するスクリプト】
124
+ ```C#
124
125
  using System.Collections;
125
126
  using System.Collections.Generic;
126
127
  using UnityEngine;
127
128
 
128
129
  public class ScoreManager : MonoBehaviour
129
130
  {
130
- [SerializeField] int m_targetScore = 5;
131
+ [SerializeField] int m_targetScore = 5;
131
- int m_score = 0;
132
+ int m_score = 0;
132
133
 
133
- public void AddScore()
134
+ public void AddScore()
134
- {
135
+ {
135
- m_score++;
136
+ m_score++;
136
- Debug.Log($"Score: {m_score}");
137
+ Debug.Log($"Score: {m_score}");
137
138
 
138
- if (m_score >= m_targetScore)
139
+ if (m_score >= m_targetScore)
139
- {
140
+ {
140
- GameClear();
141
+ GameClear();
141
- //Debug.Log(clearScore);
142
+ //Debug.Log(clearScore);
142
- }
143
+ }
143
- }
144
+ }
144
- public void GameClear()
145
+ public void GameClear()
145
- {
146
+ {
146
- Invoke("Test", 1.5f);
147
+ Invoke("Test", 1.5f);
147
- }
148
+ }
148
- private void Test()
149
+ private void Test()
149
- {
150
+ {
150
- // GameClearした時の処理
151
+ // GameClearした時の処理
151
- FadeManager.Instance.LoadScene("rizalt", 1.5f);
152
+ FadeManager.Instance.LoadScene("rizalt", 1.5f);
152
153
 
153
- }
154
+ }
154
- }
155
+ }
156
+ ```

1

書式を改善いたしました。よろしくお願い致します。

2021/08/31 08:00

投稿

kutigaiinioi-_-
kutigaiinioi-_-

スコア4

title CHANGED
@@ -1,1 +1,1 @@
1
- 一度表示したimageをック状態にするにはどうすればしいでしょうか?
1
+ 一度クリックしたimageをクリック出来ないうにいです。
body CHANGED
@@ -1,15 +1,20 @@
1
1
  現在unityでスマートフォンの間違い探しを制作しているプログラム初心者です。
2
- 間違いの場所にある透明のimageをタッチすると『marumaru』という画像が表示され、1ポイント獲得できる仕組みまでは
3
- 出来ました。
4
- ですが、タッチされて表示状態になったままの『marumaru』画像を、タッチするとタッチした分のポイントが加算されてしまいます。
5
2
 
6
- そこで質問なのですが、表示状態になっ『marumaru』画像をロック?のような状態にしてタッチしてもポイントが加算
3
+ 【やりい事】
7
- されないようにするにはどうすればよろしいでしょうか?ご教示の程、何卒よろしくお願い致します
4
+ クリックするとスコアが加算されるimageを、一度クリックしたらスコアが加算されないようにしい。
8
- ※分かり易いプレイ画面にしたいので画像を消す方法はとりたくないと考えております。
9
5
 
6
+ 【現状】
7
+ 透明のimageをクリックすると丸の画像に切り替わり得点が加算される。
8
+ しかし、その丸をもう一度クリックするとスコアが加算されてしまう。
9
+
10
+ ※正解箇所が分かるようにimageは表示し続けたいと考えております。
11
+
12
+ スクリプトの添削やもっといい方法まちがいさがしの開発方法があればご教示願いたく存じます。
10
- タッチすると『marumaru』画像表示するまでのスクリプトを以下に記します。
13
+ 画像表示やスコアに関するスクリプトを添付致しますので添削いただけますと幸いです
11
14
  よろしくお願い致します。
12
15
 
16
+ 【丸画像を表示するスクリプト】
17
+ ```C#
13
18
  using System.Collections;
14
19
  using System.Collections.Generic;
15
20
  using UnityEngine;
@@ -18,7 +23,6 @@
18
23
 
19
24
  public class maru01 : MonoBehaviour {
20
25
 
21
- public float deleteTime = 0.4f;
22
26
  public Image image;
23
27
  private Sprite sprite;
24
28
 
@@ -36,7 +40,115 @@
36
40
  image = this.GetComponent<Image>();
37
41
  image.sprite = sprite;
38
42
  }
43
+
44
+ }
45
+ }
46
+
47
+
48
+ ```
49
+
50
+ 【スコアを加算するスクリプト】
51
+ ```C#
52
+ using System.Collections;
53
+ using System.Collections.Generic;
54
+ using UnityEngine;
55
+ // 今回の追加
56
+ using UnityEngine.SceneManagement;
57
+ using UnityEngine.UI;
58
+
59
+ public class SUCORE1 : MonoBehaviour
60
+ {
61
+
62
+ public Image image;
63
+ private Sprite sprite;
64
+
65
+ // スコア関連
66
+ private int score;
67
+
68
+ public int currentScore;
69
+ public int clearScore = 5;
70
+
71
+ // Start is called before the first frame update
72
+ void Start()
73
+ {
74
+ Initialize();
75
+ }
76
+
77
+ // Update is called once per frame
78
+ void Update()
79
+ {
80
+
81
+ }
82
+
83
+ // ゲーム開始前の状態に戻す
84
+ private void Initialize()
85
+ {
86
+ // スコアを0に戻す
87
+ score = 0;
88
+
89
+ }
90
+
91
+ // スコアの追加
92
+ public void AddScore()
93
+ {
94
+ // 今回の追加
95
+ score += 1;
96
+ currentScore += score;
97
+
98
+
99
+ Debug.Log(currentScore);
100
+
101
+ if (currentScore >= clearScore)
39
102
  {
103
+ GameClear();
40
- Destroy(this.gameObject, deleteTime);
104
+ //Debug.Log(clearScore);
41
- }
105
+ }
106
+
42
- }
107
+ }
108
+ // GameClearした時の処理
109
+ // 今回の追加
110
+ public void GameClear()
111
+ {
112
+
113
+
114
+ // GameClearした時の処理
115
+ SceneManager.LoadScene("rizalt");
116
+
117
+ }
118
+
119
+ }
120
+
121
+ ```
122
+
123
+ 【スコアを管理するスクリプト】
124
+ using System.Collections;
125
+ using System.Collections.Generic;
126
+ using UnityEngine;
127
+
128
+ public class ScoreManager : MonoBehaviour
129
+ {
130
+ [SerializeField] int m_targetScore = 5;
131
+ int m_score = 0;
132
+
133
+ public void AddScore()
134
+ {
135
+ m_score++;
136
+ Debug.Log($"Score: {m_score}");
137
+
138
+ if (m_score >= m_targetScore)
139
+ {
140
+ GameClear();
141
+ //Debug.Log(clearScore);
142
+ }
143
+ }
144
+ public void GameClear()
145
+ {
146
+ Invoke("Test", 1.5f);
147
+ }
148
+ private void Test()
149
+ {
150
+ // GameClearした時の処理
151
+ FadeManager.Instance.LoadScene("rizalt", 1.5f);
152
+
153
+ }
154
+ }