Unity之一天一个技术点(十二)---指南针的实现
代码如下:
变量简述:
compassGUISkin皮肤用来显示指南针贴图
标签Label贴图用来作为指南针背景 Box贴图用来作为箭头贴图
把脚本赋予给主镜头即可
GUI.skin = compassGUISkin; var compassAngle : float = transform.rotation.eulerAngles.y;//得到镜头的y轴旋转角度 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 + yMove, 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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。