質問編集履歴
2
初心者アイコンの付加
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
1
スクリプトの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
エラーメッセージ
|
11
11
|
なし
|
12
12
|
|
13
|
-
public class Door : MonoBehaviour
|
13
|
+
~~public class Door : MonoBehaviour
|
14
14
|
{
|
15
15
|
public int count;
|
16
16
|
void OnCollisionEnter(Collision other)
|
@@ -24,8 +24,37 @@
|
|
24
24
|
}
|
25
25
|
}
|
26
26
|
}
|
27
|
-
}`
|
27
|
+
}`~~
|
28
28
|
|
29
|
+
|
30
|
+
```編集後スクリプト
|
31
|
+
```
|
32
|
+
public class Door : MonoBehaviour
|
33
|
+
{
|
34
|
+
private void Start()
|
35
|
+
{
|
36
|
+
int Dcount;
|
37
|
+
Dcount = PlayerController_Complete.count;
|
38
|
+
}
|
39
|
+
|
40
|
+
void OnCollisionEnter(Collision other)
|
41
|
+
{
|
42
|
+
if (other.gameObject.CompareTag("Player"))
|
43
|
+
|
44
|
+
{
|
45
|
+
if (Dcount >= 1)
|
46
|
+
{
|
47
|
+
Destroy(gameObject, 1.0f);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
```
|
53
|
+

|
54
|
+
Dcountのコードを追加したところ、このようなエラーが吐き出されました。
|
55
|
+
DoorのスクリプトにPlayerのcountスクリプトを入れようと思った次第です。
|
56
|
+
|
57
|
+
|
29
58
|
### 試したこと
|
30
59
|
1)Doorオブジェクトのスクリプト内でcountを5にするとDoorは削除された。
|
31
60
|
2)Playerオブジェクトのスクリプト内でcountを5にしてもDoorは削除されなかった。
|
@@ -33,4 +62,55 @@
|
|
33
62
|
|
34
63
|
### 補足情報(FW/ツールのバージョンなど)
|
35
64
|
unity2018.3.0f2
|
36
|
-
Visual Studio COmmunity 2017 ver 15.9.5
|
65
|
+
Visual Studio COmmunity 2017 ver 15.9.5
|
66
|
+
|
67
|
+
Player側のスクリプトを記載しておきます。
|
68
|
+
回答よろしくお願いします。
|
69
|
+
|
70
|
+
```
|
71
|
+
public class PlayerController_Complete : MonoBehaviour
|
72
|
+
{
|
73
|
+
|
74
|
+
Rigidbody rb;
|
75
|
+
public float speed;
|
76
|
+
public int count;
|
77
|
+
public Text countText;
|
78
|
+
|
79
|
+
// Use this for initialization
|
80
|
+
void Start()
|
81
|
+
{
|
82
|
+
rb = GetComponent<Rigidbody>();
|
83
|
+
count = 10;
|
84
|
+
SetCountText();
|
85
|
+
}
|
86
|
+
|
87
|
+
// Update is called once per frame
|
88
|
+
void FixedUpdate()
|
89
|
+
{
|
90
|
+
float moveH = Input.GetAxis("Horizontal");
|
91
|
+
float moveV = Input.GetAxis("Vertical");
|
92
|
+
|
93
|
+
Vector3 move = new Vector3(moveH, 0, moveV);
|
94
|
+
rb.AddForce(move * speed);
|
95
|
+
}
|
96
|
+
|
97
|
+
public void OnTriggerEnter(Collider other)
|
98
|
+
{
|
99
|
+
if (other.gameObject.CompareTag("A"))
|
100
|
+
{
|
101
|
+
other.gameObject.SetActive(false);
|
102
|
+
count = count + 1;
|
103
|
+
SetCountText();
|
104
|
+
}
|
105
|
+
else if (other.gameObject.CompareTag("B"))
|
106
|
+
{
|
107
|
+
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
void SetCountText()
|
111
|
+
{
|
112
|
+
countText.text = "ゲット数:" + count.ToString();
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
```
|