- Home /
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?
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;
}
}
Thanks!
Yeah for some reason I was using GameObject X = Instantiate and it wasn't working... well, worked for everything but the "scale factor"
What I meant by scale factor was simply the transform.localScale
You can change the localScale after Instantiate.
in the example, just below Instantiate call, you can do:
clone.transform.localScale = Vector3.one;
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
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 :)
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
![](https://koobas.hobune.stream/wayback/20220613085028im_/https://answers.unity.com/themes/thub/images/avi.jpg)