Issues with transform.localScale

Hey, guys. I was wondering if anyone could help me get around this issue. The logical leap just isn’t forming for me, here. I’m attempting to scale on object up over its lifetime, using the Update() function. I want to go from scale 1 to scale 5, over the course of objectLife. Here’s my incorrect code:

if(transform.localScale.x < 5)
{
transform.localScale = transform.localScale + (4f / objectLife) * Time.deltaTime;
}

The problem here is apparent in the first line. I have to use .x, because you can’t say, localScale < 5f, as it’s a Vector3. This is the same issue that occurs in the if statement’s functionality, i.e. you can’t add a float value to it. You ALSO, however, can’t add a float value to separate floats in the vector, such as:

transform.localScale.x = transform.localScale.x + (4f / objectLife) * Time.deltaTime;

They are read-only, though for what reason I can’t surmise. What can I do to circumvent this issue? As I said, the math just isn’t coming to me.

Transform.localScale.x = 5 works fine. (Unless you’re using C#, in which case you have to use a temporary variable, which Unityscript does for you, but that’s true in all cases, not just localScale.) In any case I’d recommend using Vector3.Lerp in a coroutine.

var objectLife = 5.0;

function Start () {
	ScaleOverTime (Vector3.one, Vector3(5, 5, 5), objectLife);
}

function ScaleOverTime (startScale : Vector3, endScale : Vector3, time : float) {
	var t = 0.0;
	while (t <= 1.0) {
		t += Time.deltaTime / time;
		transform.localScale = Vector3.Lerp (startScale, endScale, t);
		yield;
	}
}

–Eric