- Home /
How do i activate a function attached to a listed GameObject from the perspective of itself?
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);
}
}
}
Answer by rage_co · Sep 07, 2021 at 02:12 PM
I think it won't work like this, just put the visiblecheck funtion in the core script with a gameobject parameter.....disabling can work but enabling won't since the script too would be disabled
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
One List of GameObjects of different types... 0 Answers
Why does the script don't apply to the other duplicated player 0 Answers
Running a script without being attached to an object? 2 Answers