- Home /
This question was
closed Jan 12, 2016 at 09:26 PM by
Griffo for the following reason:
Found solution ..
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.<RectTransform>();
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;
Comment
Would be great if you could share your solution... Thanks.
Follow this Question
Related Questions
UI - clamp the movement of a panel 0 Answers
Issues rotating a UI image while the canvas is parented to the Main Camera 0 Answers
Columns/Magic Jewelry remake on Unity 0 Answers
2D UI in 3D space 3 Answers
Images order inside Canvas 1 Answer