Quantcast
Viewing all articles
Browse latest Browse all 94

Clamp UI Image to Canvas

Hi, I'm trying to clamp a UI Image that tracks incoming objects to the canvas but I'm having trouble doing it, I tracks them but then goes out of view with the object, my canvas render mode is Screen Space - Overlay .. This is the code I use to track the game object and it works fine but I want it to stay in the canvas bounds .. Any help would be appreciated .. Thanks. var CanvasRect : RectTransform = canvas.GetComponent.(); var ViewportPosition : Vector2 = cam.WorldToViewportPoint(target.position); var WorldObject_ScreenPosition : Vector2 = new Vector2(((ViewportPosition.x*CanvasRect.sizeDelta.x)-(CanvasRect.sizeDelta.x*0.5)), ((ViewportPosition.y*CanvasRect.sizeDelta.y)-(CanvasRect.sizeDelta.y*0.5))); rectTransform.anchoredPosition = WorldObject_ScreenPosition;

Viewing all articles
Browse latest Browse all 94

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>