xxxxxxxxxx
// Find all objects of a specific type in the scene
T[] objectsOfType = FindObjectsOfType<T>();
// Print the name of each object found
foreach (T obj in objectsOfType)
{
Debug.Log(obj.name);
}
xxxxxxxxxx
using UnityEngine;
public class ObjectFinder : MonoBehaviour
{
void Start()
{
// Find all objects of type 'MyScript'
MyScript[] objectsOfType = FindObjectsOfType<MyScript>();
// Iterate through the found objects
foreach (MyScript obj in objectsOfType)
{
// Do something with the object
Debug.Log("Found object: " + obj.name);
}
}
}
public class MyScript : MonoBehaviour
{
// ...
}