始终指向北指南针 [英] Always point to north compass
本文介绍了始终指向北指南针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够通过实施此处的指南来制作Compass.这是运行良好的代码.
I am able to make Compass through implementing a tutorial here. Here is the code which is working perfectly.
using UnityEngine;
using System.Collections;
/// <summary>
/// 2d GUI Compass
/// </summary>
public class CompassWithDirectionMovement : MonoBehaviour
{
#region Vars
public Transform player;
public Texture compBg;
public Texture blipTex;
#endregion Vars
#region UnityEvents
void OnGUI()
{
//GUI.DrawTexture(new Rect(0, 0, 120, 120), compBg);
//GUI.DrawTexture(CreateBlip(), blipTex);
GUI.DrawTexture(new Rect(0, 0, 120, 120), compBg);
GUI.DrawTexture(CreateBlip(), blipTex);
}
#endregion UnityEvents
#region CustomMethods
Rect CreateBlip()
{
//calculating player's angle
Debug.Log("Player LocalEulerY" + player.eulerAngles.y);
float angDeg = player.eulerAngles.y - 90;//bliper goes on Top
float angRed = angDeg * Mathf.Deg2Rad;//Convert degree to radian;
Debug.Log("Mathf.Cos(angRed) : "+ Mathf.Cos(angRed));
Debug.Log("Mathf.Sin(angRed) : "+ Mathf.Sin(angRed));
//calclulate blipper postion
float blipX = 25 * Mathf.Cos(angRed);//25 pixel from center
float blipY = 25 * Mathf.Sin(angRed);
Debug.Log("blipX : "+ blipX);
Debug.Log("blipY : "+ blipY);
blipX += 55;//half of the size of the background of compass which is center and slight minus it
blipY += 55;//
Debug.Log("blipX : "+ blipX);
Debug.Log("blipY : "+ blipY);
return new Rect(blipX, blipY, 10, 10);
}
#endregion CustomMethods
}
我想用箭头更改bliptex,但无法正常工作.失去指南针图像的中心.
I want to change bliptex with arrow but its not working correctly. loosing the center of the compass image.
推荐答案
您需要在
GUI.DrawTexture(new Rect(0, 0, 120, 120), compBg);
并在
blipX += 55;
blipY += 55;
我假设120和55是基于他正在使用的纹理大小的值,因为您使用的是其他纹理,因此需要适当地设置纹理的大小.
I assume 120 and 55 are values based size of the texture he is using, as you are using a different texture you need to set size of the texture appropriately.
希望这会有所帮助
这篇关于始终指向北指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文