Compass implementation (can be changed according to the lens rotation)
The code is as follows:
Variable Description:
Compassguiskin skin to show compass map
Tag label map used as compass background box map used as arrow map
Give the script to the main lens
Gui.skin = Compassguiskin; var compassangle:float = transform.rotation.eulerangles.y;//Gets the y axis rotation angle of the lens var compassdiameter:float = 128; var compasswidth:float = 16; var compasswindowrect:rect = Rect (Compasspos.x,compasspos.y, Compassdiameter, Compassdiameter); Gui. Label (Compasswindowrect, ""); var cosangle:float = Mathf.cos (compassangle*mathf.pi/180); var sinangle:float = Mathf.sin (compassangle*mathf.pi/180); var xmove:float = (compassdiameter*sinangle/2.0 + compasswidth*cosangle/2.0); var ymove:float = (-compassdiameter*cosangle/2.0 + compasswidth*sinangle/2.0); var Compasspos:vector3 = new Vector3 (compasspos.x + compassdiameter/2.0 + xmove,compasspos.y + compassdiameter/2.0 + YM) Ove, 0); Position for matrix var compassquat:quaternion = quaternion.identity; Rotation for matrix Compassquat.eulerangles = Vector3 (0, 0, Compassangle + 90); Set the rotation to something-rotate around z! Gui.matrIX = Matrix4x4.trs (Compasspos, Compassquat, Vector3.one); Apply The Matrix GUI. Box (Rect (0, 0, Compassdiameter, compasswidth), ""); Notice how the rect starts at 0/0 and the matrix handles the position
One day of unity a technical point (12)---compass implementation