This is for my snowball game again. As the snowball is rolling down the hill it is meant to get bigger. I want its size to increase only if the up arrow is pushed and its overall size is still less than 100. I've been using a while loop but it's not working. Any suggestions?
Try this:
var snowball : Transform; // link your snowball prefab here
var growthRate : float = 10.0; // rate at which the snowball grows
private var growthAmount : float = 0.0; // growth amount calculated every frame
function Update ()
{
if ( snowball ) // if the snowball exists
{
if (Input.GetKey ("up") // if the "up" key is held
&& snowball.localScale.x <= 100) // and the snowball scale is <= 100
{
growthAmount = growthRate * Time.deltaTime; // calculate growthAmount
snowball.localScale += new Vector3(growthAmount,growthAmount,growthAmount); // apply the growthAmount to the localScale
}
}
}
This might not fit perfectly with what you have, but as you didn't post any code, I started from scratch! I've used Time.deltaTime in the calculation to make it time-independent, and you can tune the growthRate to your needs. Hope this helps - any questions, please comment!