- Home /
Question by
daviddickball · Jul 04, 2015 at 05:46 PM ·
uilookatnavigationlookattarget
UI image to point to 3D object
I'd like a UI image of an arrow to point towards a 3D game object in my scene (the exit), but for it to remain in 2D. I use the LookAt function, but this rotates my UI element in 3D, which isn't useful as it then can't easily be seen.
transform.LookAt(target.transform);
Is there a way I can restrict the image's rotation so it only rotates in the Z axis?
Comment
Answer by fermmmm · Sep 07, 2017 at 09:38 PM
var targetPosLocal = Camera.transform.InverseTransformPoint(targetObjectPosition);
var targetAngle = -Mathf.Atan2(targetPosLocal.x, targetPosLocal.y) * Mathf.Rad2Deg - 90;
ArrowUIObject.eulerAngles = new Vector3(0, 0, targetAngle);
Your answer
Follow this Question
Related Questions
UI Navigation with gamepad 7 Answers
Indicator rotating around player 1 Answer
How can i limit gui navigation? 0 Answers
Button Navigation none - not working with touchscreen 0 Answers
LookAt doesnt work with cardboard SDK or any camera movement 0 Answers