Any idea on how to control the scale of a gameobject? I'm looking for an effect similar to Jelly Car's car object. I have a script like this: Code (csharp): var Scale : Vector3; function OnGUI() { if(GUI.Button(Rect (375,250,100,50), "Grow")) { transform.localScale.x += 1; transform.localScale.y += 1; transform.localScale.z += 1; } else { transform.localScale.x += 0; transform.localScale.y += 0; transform.localScale.z += 0; } } I want the GUI Button to grow the object in scale, but shrink back to the original size after alittle while once the button is let go. Any ideas or help would be greatly appreciated!
Hi, you could : - keep the original scale in a class variable - use a Lerp to change the scale of the cube - use a Timer (System.Timers.Timer in C#) to wait for a moment - Lerp again to re-scale the cube to its original scale In JavaScript, I don't know...maybe a SetTimeout ???
Easiest way is to make a function called "Shrink" that runs when Input.GetMouseButtonUp(0) == true. It does this: Code (csharp): yield WaitForSeconds(1); while (transform.localScale.x > holder.x) { transform.localScale.x -= 1; transform.localScale.y -= 1; transform.localScale.z -= 1; yield; } Oh, you don't need the else statement in your button, by the way. There's no point to telling it to grow by nothing if it isn't clicked.
I'm getting an error that OnGUI() cannot be a coroutine when I try to use Yield. Is there a different way to determine when the user lets go of a GUI button? I'm using Unity iPhone, so OnMouseButtonUp doesn't work
Well, don't put it in OnGUI, then. Have OnGUI start a function that runs the code when the button isn't being pressed. Code (csharp): function Shrink() { if (!started) { started = true; yield WaitForSeconds(1); while (transform.localScale.x > holder.x started) { transform.localScale.x -= 1; transform.localScale.y -= 1; transform.localScale.z -= 1; yield; } } started = false; } Add this line to your button-press: started = false; Add this variable to your script: var started : boolean = false; Add these lines to your else and dump the old lines: if (!started) { Shrink(); }