- Home /
Question by
NutellaDaddy · Dec 28, 2013 at 01:27 AM ·
objectstagfindamount
I need to store the amount of objects in scene in a var. How?
I have all of these objects in a scene under one tag name, Pickup. I want to have a script that finds all of the objects in the scene under that tag name and store them in a variable for later use. I could just write them in the script but I want a script that I can reuse in other levels.
Comment
Best Answer
Answer by aldonaletto · Dec 28, 2013 at 01:32 AM
Just get the objects with GameObject.FindGameObjectsWithTag and store its length in your variable - like this:
var pickupAmount: int; // declare the variable outside any function!
function Start(){
pickupAmount = GameObject.FindGameObjectsWithTag("Pickup").Length;
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Substitute of collision 2 Answers
How to find layer instead of tags 3 Answers
Find guiTexture objects by scripting 3 Answers
Find how many are there in the scene 1 Answer