Hi, i've got a little noob question. How can i slowly scale object's x and y from 1 to, for example, 5 during certain period of time?
This should scale an object's x and y from 1 to 5 over 10 seconds when applied to that object. Code (csharp): function Update() { var newScale : float = Mathf.Lerp(1, 5, Time.deltaTime / 10); transform.localScale = Vector3(newScale, newScale, 1); }
Code (csharp): function Update() { var newScale : float = Mathf.Lerp(1, 5, Time.time); transform.localScale = Vector3(newScale, 1, newScale); } works perfect
Well... not that perfect(( I used this script on a blood splatter sprite which is instantiated when the player is killed. But sprite is starting to scale just at the moment when the game is started, and not when it is instantiated...
Code (csharp): function Update() { if (do something here) { var newScale : float = Mathf.Lerp(1, 5, Time.time); transform.localScale = Vector3(newScale, 1, newScale); } }
Code (csharp): var finalScale = 5.0; var scaleSpeed = 2.0; function Start () { var timer = 0.0; while (timer <= 1.0) { timer += Time.deltaTime * scaleSpeed; var newScale = Mathf.Lerp(1.0, finalScale, timer); transform.localScale = Vector3(newScale, newScale, 1.0); yield; } }
Here is a combination of the above: Code (JavaScript): var SeedHeight : float; var FinalHeigh : float; var Speed : float; function Update() { var newScale : float = Mathf.Lerp(SeedHeight, FinalHeigh, Time.time*Speed); transform.localScale = Vector3(newScale, newScale, newScale); }