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
1
Question by KittenPoker · Feb 04, 2014 at 01:35 AM · instantiatescalegenerationclones

How do I get transform.localScale (C#) to apply to a clone generated by an object rather than the object the script is attached to?

I have an object to which a script is attached that generates enemies at a random time & place. I would also like to vary the size. I have seen the documentation on transform.localScale, but that just changes the size of the object the script is attached to, not the clones it generates. How do I get it to attach to the generated clone objects instead? Can I do this in script or do I need to give it various sizes of the enemy to generate from?

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
1
Best Answer

Answer by rutter · Feb 04, 2014 at 01:41 AM

Welcome to Unity Answers!

If you know which GameObject you're interested in, you can set its local scale easily enough.

You didn't mention a language, so I'll assume JavaScript:

 var go : GameObject = ...     //some GameObject
 go.transform.localScale = ... //whatever you want

The hard part, then, is figuring out which GameObject you want to edit. Your scene could contain hundreds!

The best time to get a reference to a clone is right as its made. I assume you're using Instantiate to create the clone? It returns a reference to the cloned object. You can cache that reference:

 //assumes you're cloning a GameObject
 var clone : GameObject = Instantiate(...) as GameObject;
 clone.transform.localScale = ...

Depending on what exactly you're trying to do, you can edit the clone immediately, or you can keep track of it for a while and edit it later. In some cases, it might be useful to keep a collection of clones for later reference.

Comment
Add comment · Show 1 · 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 KittenPoker · Feb 04, 2014 at 09:38 AM 0
Share

Thankyou ^_^

it was C#, but the realising I need to make a variable for each instance as it's made to be able to reference it was enough. I'm very new at this. Thankyou ^_^

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

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate Prefab Array with ID 2 Answers

how do I reference a clones of a instantiated game object and only the clones In a script? 1 Answer

How do I check the variable of a specific clone? 1 Answer

Slowly scale object to original size on instantiate 0 Answers

Just curious, assigning a clone multiple times, how does it work internally? 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