Hi, I’m having trouble with the following script:
public class Circle : MonoBehaviour
{
public GameObject[] neighbours;
private Circle circle;
void Awake ()
{
foreach (GameObject neighbour in neighbours)
{
circle = neighbour.GetComponent<Circle>();
}
}
void OnMouseDown ()
{
circle.Toggle();
}
void Toggle ()
{
// do stuff
}
}
In my scene is a bunch of circles, each with the Circle script attached. I need each circle to have access to its neighbours, so that when I click on one it toggles it toggles them.
Problem is, with the script above it’s only toggling the last neighbour in the array. How do I GetComponent of each game object in the array?