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 Lairinus · Dec 06, 2012 at 05:48 AM · c#gameobjectinstantiatescaling

Scaling an instantiated object based on prefab, but not prefab

Hello!

Since the game object won't scale through using variables that are linked to instantiation (well, without re-scaling the prefab, itself), I was planning on using a GameObject.Find() component to scale it manually.

However, is there a way to reference THAT model?

Basically what I'm saying is if I have like 5 clones of a model up, certainly GameObject.Find() won't return the right one... so how do I make it do so? Is there a feature like...

GameObject instantiate.....; GameObject.Find(lastCreatedGameObject);

or is it a hell of a lot more complex than that?

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

2 Replies

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

Answer by astorga · Dec 06, 2012 at 04:44 PM

"Instantiate" returns the created GameObject. You just need to get its return to a variable (taken from manual):

 // Instantiate a prefab with an attached Missile script
 var projectile : Missile;
 
 function Update () {
     // Ctrl was pressed, launch a projectile
     if (Input.GetButtonDown("Fire1")) {
         // Instantiate the projectile at the position and rotation of this transform
         var clone : Missile;
         clone = Instantiate(projectile, transform.position, transform.rotation);
         
         // Set the missiles timeout destructor to 5
         clone.timeoutDestructor = 5;
     }
 }


Comment
Add comment · Show 5 · 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 Lairinus · Dec 07, 2012 at 05:18 AM 0
Share

Thanks!

Yeah for some reason I was using GameObject X = Instantiate and it wasn't working... well, worked for everything but the "scale factor"

avatar image astorga · Dec 07, 2012 at 11:30 AM 0
Share

What do you mean by "scale factor"?

avatar image Lairinus · Dec 07, 2012 at 08:59 PM 0
Share

What I meant by scale factor was simply the transform.localScale

avatar image astorga · Dec 07, 2012 at 10:36 PM 0
Share

You can change the localScale after Instantiate.

in the example, just below Instantiate call, you can do:

 clone.transform.localScale = Vector3.one;
avatar image Lairinus · Dec 07, 2012 at 11:08 PM 0
Share

Yeah I do have it working now, I'm sorry if I confused you.

That's exactly what I did and it's working fine now :D

avatar image
0

Answer by BilboStabbins · Dec 06, 2012 at 04:25 PM

One way to keep track would be to instantiate them and add them to a list / array at the same time. That way you can reference the indexes for which one you want to scale. You can use List.Count to see how many objects are currently in the List and then access the last one in.

Hope that helps :)

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 Lairinus · Dec 07, 2012 at 05:20 AM 0
Share

Thanks for the response; I voted the other one up just because of the inherent ease versus that response. But you did kind of explain exactly what I would need in the future.

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

11 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

Related Questions

Instantiated GameObject Not Rendering 1 Answer

How can I add the OnTriggerEnter function to all game objects that I instantiate? 1 Answer

C# instantiate into list 2 Answers

Instantiate prefab at specific path 1 Answer

Thrown objects always have same rotation 2 Answers


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