x


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(objectAdd){
                 addAnObject();
         }
         if(fullScaleObject == 2){
                 Debug.Log("COMPLETE");
         }
         if(objectCount[0].transform.localScale.y >= 1.0){
                 if(!runonce){
                     addAnObject = true;
                     runonce = true;
                 }
         }
         if(objectCount[1].transform.localScale.y >= 1.0){
                 if(!runagain){
                         addAnObject = true;
                     runagain = true;
                 }
         }
 }

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

Thanks - C

more ▼

asked Apr 19, 2011 at 12:57 PM

Caiuse gravatar image

Caiuse
882 259 206 225

(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:

scaleScript.js

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

Kourosh gravatar image

Kourosh
1.6k 138 103 117

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

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
(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

By RSS:

Answers

Answers and Comments

Topics:

x3702
x2290
x2289

asked: Apr 19, 2011 at 12:57 PM

Seen: 1709 times

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