2

The following code:

Debug.LogWarning("updating scale fix, scalefactor: "+scaleFactor+" - Current scale is: "+cell.transform.localScale.x);
cell.transform.localScale.Set (scaleFactor,scaleFactor,scaleFactor);
Debug.LogWarning("Scale after fix: " + cell.transform.localScale.x);

Produces the following output:

updating scale fix, scalefactor: 0.9 - Current scale is 0.8921105
UnityEngine.Debug:LogWarning(Object)

Scale after fix: 0.8921105
UnityEngine.Debug:LogWarning(Object)

Any ideas? I would just assume that since these things are happening right after each other, the scale should be updated. Or does that happen after a frame has completed?

Any help is appreciated.

Steven
  • 166,672
  • 24
  • 332
  • 435
Salx
  • 579
  • 5
  • 21

1 Answers1

6

localScale is a property so it returns a copy of the real localScale (Vector3 is a struct) Try cell.transform.localScale = new Vector3 (scaleFactor, scaleFactor, scaleFactor); or cell.transform.localScale = Vector3.one * scaleFactor;

artemisart
  • 190
  • 1
  • 7
  • 1
    Spot on. [A little more background reading for OP](http://stackoverflow.com/questions/9251608/are-structs-pass-by-value). – rutter Feb 04 '14 at 02:26
  • This worked, thanks. One question I had though was that the .Set(x,y,x) was assumed to be used for this purpose. And yet, I do not see any documentation on it. – Salx Feb 05 '14 at 22:46
  • But how to scale it from one point e.g. From Left to right? Is it possible to set pivot position programatically? – Rajneesh Gaikwad Oct 11 '14 at 12:44
  • Yes, you can change `transform.position` and `transform.localPosition`. – artemisart Oct 11 '14 at 16:32