質問編集履歴

3

状況を詳しく記載しました。

2020/06/29 08:20

投稿

itirou
itirou

スコア3

test CHANGED
File without changes
test CHANGED
@@ -9,6 +9,10 @@
9
9
  空のオブジェクトの中に駒のオブジェクト、移動範囲のオブジェクトを入れて、
10
10
 
11
11
  下記のスクリプトを駒のオブジェクトにアタッチし、komaの変数に空のオブジェクト、hanniの変数に移動範囲のオブジェクトを入れて一つの駒を管理しようとしています。
12
+
13
+
14
+
15
+ 駒をクリックした時に移動範囲が表示される。移動範囲のいずれかをクリックし、その場所に駒が移動するようにしたいと思い下記のスクリプトを書きました。
12
16
 
13
17
 
14
18
 

2

状況を詳しくしました。

2020/06/29 08:20

投稿

itirou
itirou

スコア3

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,26 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
+ Unity初心者です。
4
+
3
- Unity2D(ver.2029.3.8f1)でチェスのようなゲームを作っているのだが、駒のオブジェクトを選択した際に、別の駒のオブジェクトも一緒に選択されてしうので、クリックしたオブジェクト”のみ”選択されるようにしたい
5
+ Unity2D(ver.2029.3.8f1)でチェスのようなゲームを作っていま
4
6
 
5
7
 
8
+
9
+ 空のオブジェクトの中に駒のオブジェクト、移動範囲のオブジェクトを入れて、
10
+
11
+ 下記のスクリプトを駒のオブジェクトにアタッチし、komaの変数に空のオブジェクト、hanniの変数に移動範囲のオブジェクトを入れて一つの駒を管理しようとしています。
12
+
13
+
14
+
15
+ これを別の駒のオブジェクトに同じようにアタッチしたのですが、実行して駒をクリックした時選択した駒のオブジェクトだけでなく別の駒のオブジェクトも一緒に選択されてしまいます。
16
+
17
+
18
+
19
+ クリックした駒だけが選択され移動できるようにしたいのですがどうしたらいいでしょうか。
20
+
21
+
22
+
23
+ (boolでtrueなら動かせる、farseなら動かせないようにし、駒をクリックした時にその駒がtrueになるようにしようと思ったのですがboolの使い方がよくわかっておらず、どこにどのように記述したらいいかわかりません。ほかにいい方法があったらおしえていただきたいです。)
6
24
 
7
25
  ### 発生している問題・エラーメッセージ
8
26
 
@@ -18,19 +36,25 @@
18
36
 
19
37
  using UnityEngine;
20
38
 
39
+ using UnityEngine.UI;
21
40
 
22
41
 
42
+
23
- public class idou: MonoBehaviour
43
+ public class idou : MonoBehaviour
24
44
 
25
45
  {
26
46
 
27
47
  public GameObject koma;
28
48
 
29
- public GameObject idouhanni ;
49
+ public GameObject idouhanni;
30
50
 
31
-
51
+ public bool myturn;
32
52
 
33
-
53
+
54
+
55
+
56
+
57
+
34
58
 
35
59
  private GameObject GetClickObject()
36
60
 
@@ -38,7 +62,7 @@
38
62
 
39
63
  GameObject result = null;
40
64
 
41
-
65
+
42
66
 
43
67
  if (Input.GetMouseButtonDown(0))
44
68
 
@@ -64,7 +88,7 @@
64
88
 
65
89
 
66
90
 
67
-
91
+
68
92
 
69
93
  void Update()
70
94
 
@@ -80,9 +104,9 @@
80
104
 
81
105
  }
82
106
 
83
- GameObject objs = GetClickObject();
107
+
84
108
 
85
- if (objs != null)
109
+ if (obj != null)
86
110
 
87
111
  {
88
112
 
@@ -90,8 +114,6 @@
90
114
 
91
115
  }
92
116
 
93
-
94
-
95
117
  }
96
118
 
97
119
  }

1

変数の名前変更

2020/06/29 08:17

投稿

itirou
itirou

スコア3

test CHANGED
File without changes
test CHANGED
@@ -20,11 +20,11 @@
20
20
 
21
21
 
22
22
 
23
- public class Kingidou: MonoBehaviour
23
+ public class idou: MonoBehaviour
24
24
 
25
25
  {
26
26
 
27
- public GameObject king;
27
+ public GameObject koma;
28
28
 
29
29
  public GameObject idouhanni ;
30
30
 
@@ -76,7 +76,7 @@
76
76
 
77
77
  {
78
78
 
79
- king.transform.position = GetClickObject().transform.position;
79
+ koma.transform.position = GetClickObject().transform.position;
80
80
 
81
81
  }
82
82