我试图理解 GetComponent,但我很难弄清楚如何编写语法。我有两个脚本(SpawnBehaviour 和 SpotClicked)并希望从“SpawnBehaviour 到 SpotClicked.
如何获得正确的语法,并将 SpawnBehaviour 中的布尔值更改为 true?
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;