我試圖理解GetComponent,但我很難弄清楚如何編寫語法。我有兩個腳本(SpawnBehaviour和SpotClicked),並希望得到來自「SpawnBehaviour的布爾到SpotClicked。如何使用GetComponent-語法
如何獲得語法正確,並更改SpawnBehaviour布爾爲真?
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
if(this.gameObject.tag == "fishSpot"){
Debug.Log("Clicked "+gameObject.name);
//get "stopped"bool from "SpawnBehaviour" script and set it to true
SpawnBehaviour sb = spawnPoint.GetComponent<SpawnBehaviour>().stoppedSpawn=true;
}
}
在SpawnBehaviour.cs我有
public bool stoppedSpawn = false;
我不斷地收到「不能隱式輸入'bool'到'spawnBehaviour' – Eyrik
因此,讓我看看你正在使用的代碼,將它編輯到你的問題中 – Bart
已更新我的代碼 – Eyrik