Question by
Hellhound_01 · Nov 10, 2017 at 10:23 AM ·
gameobjectui image
How to determine an object position on ui texture?
I'm rendering a 3d object to a texture (2048x1600), which is shown on a UI Panel (1600x285) using a RawImage component (2048x1600). The object contains several empty objects for the definition of mountpoints. Now I try to render a sprite on UI texture at the position of the mountpoint (must not be pixel perfect). How I could archive this?
I tried to use several camera transform, which doesn't return correct results:
var main = camera.WorldToScreenPoint(slot.mountpoint.position);
Debug.Log("Maincam screenpos: " + main.ToString());
RectTransform rect = this.GetComponentInParent<RectTransform>();
Debug.Log("Rect size delta: " + rect.sizeDelta.ToString());
Vector2 viewPos = camera.WorldToViewportPoint(slot.mountpoint.position);
Debug.Log("Viewport pos : " + viewPos.ToString());
Vector2 localPos = new Vector2(viewPos.x * rect.sizeDelta.x, viewPos.y * rect.sizeDelta.y);
Debug.Log("Viewport pos local : " + localPos.ToString());
I'm running out of ideas. Thanks for any help.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612142642im_/https://answers.unity.com/themes/thub/images/avi.jpg)