- Home /
How do I change the rect transform value of a slider?
I want to change the value "right" but it returns me with an error that it isnt a variable.
This is the error I get when I try to access the rect:
printing does give me a value, how can I change it through script though?
Answer by Baste · May 01, 2015 at 11:59 AM
You'll have to fetch the Rect, change the value, and reset it:
Rect rect = bg.rect;
rect.xMax = 100;
bg.rect = rect;
This has to do with Rects being structs, not objects. So when you do this:
bg.rect
you're getting a copy of the value of the Rect, not the same rect as the one on the bg object. . Meaning that it would be completely possible to let you do this:
bg.rect.xMax = 100
but the value would just be changed on a copy that you've already lost access to (a new call to bg.rect would give a new copy), so the line would do literally nothing.
Nice, I can now access the variable but I cannot change it, nothing seems to happen when I for example do:
rect.x$$anonymous$$ax -= 10;