- Home /
How to determine Canvas scale factor when using Canvas Scaler
I am trying to put calibration marks (images) onto a slider object.
Logic is simple: get slider width like this:
RectTransform tmpSlider = timerSlider.transform as RectTransform;
float wid = tmpSlider.sizeDelta.x;
Divide width by 10 to get space between calibration; (calibration marks at every 10%)
float calibspace = wid/10f;
Position image
greenMarker1.transform.position = new Vector3( greenMarker1.transform.position + 10f), greenMarker1.transform.position.y, greenMarker1.transform.position.z);
greenMarker2.transform.position = new Vector3( greenMarker2.transform.position + 10f), greenMarker2.transform.position.y, greenMarker2.transform.position.z);
etc
markers are originally set to x = 0 and pivot is 0, 0.
This works (I think) but is not being scaled correctly because 'wid' is always the same value (in this case 208) regardless of screen resolution. And its the same value as in the inspector.
I obviously need to apply the same scale factor to this as is being done bythe canvas scaler, but I can find no reference to that value being exposed.
Any pointers in the right direction would be greatly appreciated.
Thanks
Dave
Hi. I have the same issue. I have a custom LayoutGroup that uses sizeDelta. I don't know how this is suppose to work, but multiplying with RectTransform.lossyScale seems to do what we want. I'd also like some clarification this.
Your answer
Follow this Question
Related Questions
Unity 2D GameObject Movement.(C#) 0 Answers
Parent with animator component prevents child buttons to get click 0 Answers
Custom Dropdown Sorting Order problem 2 Answers
Text smaller on Android 0 Answers