So, i am trying to create a script that turns on / off GameObjects (“Cells”) based on the list of values each of those GameObjects have within an attached script, These GameObjects are currently within its own list within the “CellManager” (Core) Script. So that the amount of Cells is flexible i am attaching the same secondary script that refers to itself, however i am having trouble defining what the script is affecting.
This is my Core Script:
public class CellManager : MonoBehaviour
{
public GameObject[] CellSet;
public int CellSetNum = 0;
public void ActivateCheck()
{
foreach (var obj in CellSet)
{
GameObject go = GameObject.Find(obj.name);
Cellbehave other = (Cellbehave)go.GetComponent(typeof(Cellbehave));
other.VisibleCheck();
}
}
public void NextCellSet()
{
CellSetNum += 1;
//Complete a Check
ActivateCheck();
}
public void BackCellSet()
{
CellSetNum -= 1;
//Complete a Check
ActivateCheck();
}
This is my Other Script that is attached to each of the Listed GameObjects within “Cellset”.
public class Cellbehave : MonoBehaviour
{
public List<int> MyNumbers;
private int CellNum;
public void VisibleCheck()
{
CellNum = GameObject.Find("NovelManager").GetComponent<CellManager>().CellSetNum;
Debug.Log("VisibleChecking...");
bool isInList = MyNumbers.IndexOf(CellNum) != -1;
if (isInList)
{
this.gameObject.SetActive(true);
}
else
{
this.gameObject.SetActive(false);
}
}
}