One day of unity a technical point (12)---compass implementation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.