Hello,
I want to be able to smoothly increase/decrease the scale.y of my object.
Basically, I have a variable that will randomly range between 1 and 10 every second, and I want this variable to effect the scale.y of a certain object.
In other words, if var random = 5, then scale.y will also =5, if the var random changes to, say 8, then scale.y will smoothly/gradually increase to 8 too.
How will this be achieved? Lerp?
Here is where I'm at:
function Start(){
while(true){
oldScale = sizeY;
sizeY = Random.Range(1, 11);
newScale = sizeY;
yield WaitForSeconds(0.2);
}
}
private var speed : float = 1;
var oldScale : int;
var newScale : int;
var oldScaleVec : Vector3;
var newScaleVec : Vector3;
function Update (){
oldScaleVec = Vector3(1, oldScale, 1);
newScaleVec = Vector3(1, newScale, 1);
cube.transform.localScale = Vector3.Lerp(oldScaleVec, newScaleVec, Time.deltaTime / 2);
}
This kind of works, although it's not animating it - more like jumping straight to the new given value.
↧