- Home /
Now I'm over Inflated!
So i have been working on this balloon script and thanks to the help of people here i have now got my balloon appearing all over the place and have them inflating (getting bigger) over time, but...
It only works on the first instance. Every subsequent clone is already big. Now I expect this is cos I am so silly that i dont know how to combine the code properly so I have the get bigger code on my balloon and the create instance on a game object.
So my question is how do i combine these two code so that each instance grows as it is created. Sorry to be such a dummy but im new but learning fast.
My simple instance code
var projectile : Rigidbody;
function Update () {
if (Input.GetButtonDown("Fire1")) {
var clone : Rigidbody;
clone = Instantiate(projectile, transform.position, transform.rotation);
clone.velocity = transform.TransformDirection (Vector3(0, -1, 0) * 12);
}
}
And my scale script
var bigScale : Vector3 = Vector3(30,30,30);
var myTime : float = 1.0;
function Update ()
{
transform.localScale = Vector3.Lerp(transform.localScale,bigScale,Time.deltaTime * myTime);
}
A little more help we see me through.
Thanks
Sorry - should have posted separately. They are separate and on separate object. But I think they both need to be part of the instance script.
Answer by Oliver Eberlei · Jun 18, 2011 at 10:02 AM
What do you put into your projectile variable? Is it a GameObject that is already in the scene? Try creating a prefab instead. Otherwise, if the GameObject you clone grows in size, you will clone the increased size aswell.
By using a prefab your newly created clone will always be in its default state, since it never was in the scene and therefore didn't grow before.
Exactly and watch out, if a script that is part of a prefab hold a reference to itself, it will point to the instantiated clone after it's instantiated. So if the instance tries to create another instance it clones the instance and not the prefab.
Some call it a bug, but i guess it's intended behaviour ;) As long as your instantiate script is not part of the prefab itself there's not problem, as long as you assigned the prefab to the variable and not an instance from the scene.
Hey thanks - i am putting the projectile var onto an empty game object. The Variable is a cube (just for testing) that has the scale object on. So will try with a prefab and let yo know how it goes. Its 1.00am now so will have to wait till the morning. Cheers.
Your answer