0

How can I change an object's X axis scale over time? I tried this code:

transform.localScale.x *= 1.1f;

But it gives me this error:

Cannot modify the return Value of "Transform.localScale" because it is not a variable

Taik
  • 265
  • 9
  • 28

1 Answers1

2

To change just a single value in localScale, you'll need to create a new Vector3 locally. Two examples of doing this:

// Make a new vector with identical y and z values, but with a new x value.
var newScale = new Vector3(
    transform.localScale.x * 1.1f,
    transform.localScale.y,
    transform.localScale.z);

// Set scale to the new Vector3.
transform.localScale = newScale;

An alternative:

// Copy into a variable. We can now make per-value changes.
var newScale = transform.localScale;
newScale.x *= 1.1f;

// Copy back into the transform.
transform.localScale = newScale;
Not so Veteran
  • 318
  • 3
  • 9