Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Caiuse · Apr 19, 2011 at 12:57 PM · gameobjecttransformarray

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Kourosh · Apr 19, 2011 at 01:54 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Toxic Blob · Apr 19, 2011 at 02:26 PM 1
Share

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.

avatar image Caiuse · Apr 20, 2011 at 10:50 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

C# Variables Transform vs GameObject 1 Answer

Getting the transform from a GameObject list 3 Answers

Keep adding targets to a list 2 Answers

How do I check multiple gameObjects transform positions? 3 Answers

Instantiating from an object that's in an array 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges