回答編集履歴
2
無駄を省きました。
test
CHANGED
@@ -23,36 +23,33 @@
|
|
23
23
|
}
|
24
24
|
else if(Input.GetMouseUp(0))
|
25
25
|
{
|
26
|
+
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
27
|
+
RaycastHit2D afterHit2D = Physics2D.Raycast((Vector2)ray.origin, (Vector2)ray.direction);
|
28
|
+
|
26
|
-
if(
|
29
|
+
if(beforeHit2D && afterHit2D)
|
27
30
|
{
|
28
|
-
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
29
|
-
|
31
|
+
MyImageComponent myImageComponent = afterHit2D.GetComponent<MyImageComponent>();
|
30
|
-
|
31
|
-
if(
|
32
|
+
if(myImageComponent)
|
32
33
|
{
|
33
|
-
My
|
34
|
+
MyButtonComponent1 myButtonComponent1 = beforeHit2D.GetComponent<MyButtonComponent1>();
|
34
|
-
if(my
|
35
|
+
if(myButtonComponent1)
|
35
36
|
{
|
37
|
+
myImageComponent.MyFunction1(myButtonComponent1.GetNum()); //myButtonComponent1.GetNum() は MyButtonComponent1 にあるゲッター
|
38
|
+
}
|
36
|
-
|
39
|
+
MyButtonComponent2 myButtonComponent2 = beforeHit2D.GetComponent<MyButtonComponent2>();
|
37
|
-
|
40
|
+
if(myButtonComponent2)
|
38
|
-
|
41
|
+
{
|
39
|
-
|
42
|
+
myImageComponent.MyFunction1(myButtonComponent2.GetNum());
|
40
|
-
|
43
|
+
}
|
41
|
-
|
44
|
+
MyButtonComponent3 myButtonComponent3 = beforeHit2D.GetComponent<MyButtonComponent3>();
|
42
|
-
|
45
|
+
if(myButtonComponent3)
|
43
|
-
|
46
|
+
{
|
44
|
-
|
47
|
+
myImageComponent.MyFunction1(myButtonComponent3.GetNum());
|
45
|
-
|
48
|
+
}
|
46
|
-
|
49
|
+
MyButtonComponent4 myButtonComponent4 = beforeHit2D.GetComponent<MyButtonComponent4>();
|
47
|
-
|
50
|
+
if(myButtonComponent4)
|
48
|
-
|
51
|
+
{
|
49
|
-
myImageComponent.MyFunction1(myButtonComponent3.GetNum());
|
50
|
-
}
|
51
|
-
MyButtonComponent4 myButtonComponent4 = beforeHit2D.GetComponent<MyButtonComponent4>();
|
52
|
-
if(myButtonComponent4)
|
53
|
-
{
|
54
|
-
|
52
|
+
myImageComponent.MyFunction1(myButtonComponent4.GetNum());
|
55
|
-
}
|
56
53
|
}
|
57
54
|
}
|
58
55
|
}
|
1
簡易的なコードに書き換えました。
test
CHANGED
@@ -30,32 +30,28 @@
|
|
30
30
|
|
31
31
|
if(beforeHit2D && afterHit2D)
|
32
32
|
{
|
33
|
-
My
|
33
|
+
MyImageComponent myImageComponent = afterHit2D.GetComponent<MyImageComponent>();
|
34
|
-
if(my
|
34
|
+
if(myImageComponent)
|
35
35
|
{
|
36
|
-
My
|
36
|
+
MyButtonComponent1 myButtonComponent1 = beforeHit2D.GetComponent<MyButtonComponent1>();
|
37
|
-
if(my
|
37
|
+
if(myButtonComponent1)
|
38
38
|
{
|
39
|
-
myImageComponent
|
39
|
+
myImageComponent.MyFunction1(myButtonComponent1.GetNum()); //myButtonComponent1.GetNum() は MyButtonComponent1 にあるゲッター
|
40
40
|
}
|
41
|
-
My
|
41
|
+
MyButtonComponent2 myButtonComponent2 = beforeHit2D.GetComponent<MyButtonComponent2>();
|
42
|
-
if(my
|
42
|
+
if(myButtonComponent2)
|
43
43
|
{
|
44
|
-
myImageComponent
|
44
|
+
myImageComponent.MyFunction1(myButtonComponent2.GetNum());
|
45
45
|
}
|
46
|
-
}
|
47
|
-
MyButtonComponent
|
46
|
+
MyButtonComponent3 myButtonComponent3 = beforeHit2D.GetComponent<MyButtonComponent3>();
|
48
|
-
if(myButtonComponent
|
47
|
+
if(myButtonComponent3)
|
49
|
-
{
|
50
|
-
MyImageComponent1 myImageComponent1 = afterHit2D.GetComponent<MyImageComponent1>();
|
51
|
-
if(myImageComponent1)
|
52
48
|
{
|
53
|
-
myImageComponent
|
49
|
+
myImageComponent.MyFunction1(myButtonComponent3.GetNum());
|
54
50
|
}
|
55
|
-
My
|
51
|
+
MyButtonComponent4 myButtonComponent4 = beforeHit2D.GetComponent<MyButtonComponent4>();
|
56
|
-
if(my
|
52
|
+
if(myButtonComponent4)
|
57
53
|
{
|
58
|
-
myImageComponent
|
54
|
+
myImageComponent.MyFunction1(myButtonComponent4.GetNum());
|
59
55
|
}
|
60
56
|
}
|
61
57
|
}
|