I'm trying to access gameobject array values from one script to another. I have attached certain gameobject capsules with the array in the editor as shown in the figure below and I'm trying to access the values of array to another script. But I get null values when i try to pass the values. I don't want to use gameobject tag since i have to set gameobject active and deactive during runtime.
PinsScript.cs
public class PinsScript : MonoBehaviour {
// Use this for initialization
public GameObject[] pins;
void Start () {
}
// Update is called once per frame
void Update () {
}
}
MovingBall.cs
PinsScript p = GetComponent<PinsScript>();
foreach (GameObject pin in p.pins)
{
pin.SetActive(false);
}
PinsScript p = GetComponent<PinsScript>();
is wrong. Because, it's trying to find the PinsScript component in the same gameObject, which is not there, as you said. \$\endgroup\$