Simple Vector question

In my javascript script i had the line

scaleX = transform.localScale.x;
transform.localScale.x = scaleX *-1;

but when I do it on c#, it gives me the errorw here i need a temp variable. i cant figure this out fo the life of me. ive done this problem similar parts of code, but i cant fidn the soolution to this

scaleX = transform.localScale.x;
transform.localScale = new Vector3(scaleX*-1f,transform.localScale.y,transform.localScale.z);

You can’t modify directly an x,y or z value from those vector. You need to reassign a new vector with the correct value.

Vector3 myScale = transform.localScale;
myScale.x *= -1;
transform.localScale = myScale;

You cannot edit parts of those vectors directly, you need to assign an entire Vector3.

yeah i know that. i just cant really figure out how to do that

Ambro pretty much gave you the code to do it?

    scaleX = transform.localScale.x;
    transform.localScale = new Vector3(scaleX*-1f,transform.localScale.y,transform.localScale.z);

You can’t access the components of a Vector3 (x,y,z) as they are encapsulated within the transform class.

We just gave you two examples of how to solve this.

Really spot on with timing today…

whoops, misread it xD