In my program, a variable isn’t available from a void.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour {
[Space]
[Header("Tiles")]
public GameObject Tiles;
public GameObject[,] tiles = new GameObject[8,8];
public void Start()
{
for (int i = 0; i < 8; i++)
{
Transform parent = Tiles.transform.GetChild(i);
for (int j = 0; j < 8; j++)
{
tiles[i, j] = parent.GetChild(j).gameObject;
tiles[i, j].gameObject.GetComponent<Tile>().PosInput(i, j);
}
}
tiles[3, 0].transform.position = new Vector3(0f, 10f, 0f); //<-- Here the tiles[3,0] GameObject gets moved to (0f,10f,0f)
}
//On Mouse Click
public void Input()
{
tiles[3, 0].transform.position = new Vector3(1f, 10f, 0f); //<-- But here it doesn't. It says the there's no GameObject in tiles[3,0]
}
}