Hi im very new to Unity and C#. My terminology might not be on lock. I have a question that i think is pretty simple. This has probably been asked a million times, but i cant seem to find one that matches exactly what im trying to do. Im trying to make multiple GameObjects appear when my Player enter a Trigger. Right now im referring to each GameObject individually in my script 'cause i cant figure out how to use GameObject and .FindGameObjectsWithTag. My script works for the first gameobject named floating1 and in that way i know if i duplicated the lines and just changed the name to match the objects i would have something that works, i think. I could also make individual scripts for each object and that would work too, if i somehow could refer to the same trigger on the parent.
But isnt there a smarter way to do this?
Here is the code:
public GameObject f1;
public GameObject f2;
public GameObject f3;
public GameObject f4;
private GameObject[] foundObjects;
// Use this for initialization
void Start()
{
if (foundObjects.Length == 0)
foundObjects = [];
foundObjects = GameObject.FindGameObjectsWithTag("cubesPulse");
foreach (GameObject obj in foundObjects)
{
//every gameobject in scene with tag "cubesPulse"
obj.SetActive(false);
}
}
private void onTriggerEnter(Collider other)
{
if (other.Comparetag("Player"))
{
foreach (GameObject obj in foundObjects)
{
//every gameobject in scene with tag "cubesPulse"
obj.SetActive(true);
}
}
}