Before updating to Windows 10 you may need to return your Pro license. More information here

Access Transform of an Array of GameObjects

Okay I know this is such a long winded way of writing it but I gave it a go, could anyone possible explain how I can simplify this whole piece of script.

To explain what I'm doing: I have two game objects that are instantiated at different points in my game, both scale from 0.01 to 1.00, I want the script to recognize when both objects have been instantiated and when they're both full scale.

var runonce = false; var runagain = false; var objectAdd = false; var fullScaleObject = 0;

 function Update(){
         var objectCount : GameObject[] = gameObject.FindGameObjectsWithTag("myObject");
         if(fullScaleObject == 2){
         if(objectCount[0].transform.localScale.y >= 1.0){
                     addAnObject = true;
                     runonce = true;
         if(objectCount[1].transform.localScale.y >= 1.0){
                         addAnObject = true;
                     runagain = true;

 function addAnObject(){
         fullScaleObject += 1;
         objectAdd = false;

Thanks - C

more ▼

asked Apr 19, 2011 at 12:57 PM

avatar image

940 260 207 227

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Why don't you attach a single script to each object that you want scaled:


var increment:float; var speed:float = 0.001; var originalScale:Vector3;

function Start(){ originalScale = transform.localScale; transform.localScale = Vector3.zero; } function LateUpdate(){ transform.localScale = Vector3.Lerp(transform.localScale,originalScale,increment ); if(increment <1) increment += speed; }

so they we'll be scaled to their original scale from zero, as soon as they are instantiated.

more ▼

answered Apr 19, 2011 at 01:54 PM

avatar image

1.6k 138 103 117

This seems the simplest way to go. scaleScript.js could then also message your manager script when instantiated, and when at scale 1. Your manager script could then keep track of how many messages it's received and respond accordingly when all objects have reported in.

Apr 19, 2011 at 02:26 PM Toxic Blob

Okay I wasn't really after a scaling script, probably bad explanation on my behalf. I just wanted an simple way of writing what I have in the script above... but your suggestion of sending a message to the manager when the object have scaled fully works a treat, so you've indirectly answered my question! Thanks.

Apr 20, 2011 at 10:50 AM Caiuse
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Apr 19, 2011 at 12:57 PM

Seen: 1804 times

Last Updated: Apr 19, 2011 at 01:02 PM