in my scene i have 10 objects with a tag and another 10 with a different tag, which would be better to do
store them all in an array in my script
or
just use find gameObjects with tag
i will need to use these objects frequently switching from which set can be used, so would it be better to store them as an array of objects inside my script. if its not very clear i will try to give information.
Technically it can be ok to do both
private var objs1:GameObject[];
private var objs2:GameObject[];
function Start()
{
objs1=GameObject.FindGameObjectsWithTag("Object1");
objs2=GameObject.FindGameObjectsWithTag("Object2");
}
Since you only do a find once it isnt bad, if the objects update during runtime you need to alter the methods used. You can set these variables to public and add a length check to see if you need to run a find…like this
public var objs1:GameObject[];
function Start()
{
if(!objs1)objs1=GameObject.FindGameObjectsWithTag("Object1");
}
this way if you set them in the inspector you dont need to find the objects, and if you forget to set them ahead of time you have a backup.
If you another concern, please add them to the comments