Seeking clones of instantiated objects with C# script

I want the player to trigger a script that checks for all instantiated prefabs, and destroys them when they’re too far away.

I’m successfully using an instantiate trigger script using C# but actually having the following issue:

In C# i have to specify the type of the object and cast to it in order to be able to manipulate the properties. This is particularly important if i instantiate a prefab object and want to edit it on the fly. The problem i am having is that the gameobjects and prefabs aren’t recognized as valid types, even though everything i read indicates they should be. The error happens at compile time, so i can’t even compile it. Normally in C# you would just add the correct namespace to reference an type, but in Unity3d i am not sure what i need to do and online searches haven’t helped. Error is here below.

error CS0246: The type or namespace name `GameObjectNameHere’ could not be found. Are you missing a using directive or an assembly reference?

For example, i can’t type public GameObjectName testName = (GameObjectName)Instantiate(parm1,parm2,parm3);

Thanks for any help!!

I didn’t quite follow that - can you perhaps provide a concrete example? It sounds like you might be confused as to what a ‘type’ is, but it’s hard to say for sure based on what you posted.

What is GameObjectName supposed to represent in your example? Is it the name of a custom script you’ve written? Something else?

I think you want to use this instead.

GameObject testName = (GameObject)Instantiate(parm1,parm2,parm3);

then testName with hold a reference to the new GameObject

idk what GameObjectName is