Hi ı have 8 buttons and their names are button_1 button_2… button_8.Im trying to save as gameobject and every 8 buttons has this script cause ım using onmouseover and every one of them has to has this right? I m getting nullreference on line 8 İt works when ı add buttons=new Gameobject[8]. I dont understand why ı have to declare arrays size.Just take what ı give
GameObject[] buttons;
private void Awake()
{
for(int i = 0; i < 8; i++)
{
for (int a = 1; a < 9; a++)
{
buttons[i] = GameObject.Find("button_"+a.ToString());
}
}
}
void Start()
{
for (int a = 2; a < buttons.Length; a += 2)
{
// buttons[a].SetActive(false);
}
}
// Update is called once per frame
void Update()
{
}
private void OnMouseOver()
{
hide_button();
}
private void OnMouseExit()
{
}
void hide_button()
{
switch(gameObject.name)
{
case "1":
buttons[2].SetActive(true);
break;
case "3":
buttons[2].SetActive(true);
break;
case "5":
buttons[2].SetActive(true);
break;
case "7":
buttons[2].SetActive(true);
break;
}
}