更新UI上image的旋转与transform的旋转一致
using UnityEngine;
using System.Collections;
[AddComponentMenu("MiniMap/Map arrow")]
public class MapArrow : MonoBehaviour
{
private RectTransform ArrowRect;
void Awake()
{
ArrowRect = transform.GetComponent<RectTransform>();
}
public Transform playerTransform;
private bool rotateMap;
void Update()
{
if (rotateMap)
{
rotate(Quaternion.identity);
}
else
{
rotate(Quaternion.Euler(new Vector3(0, 0, -playerTransform.eulerAngles.y)));
}
}
/// <summary>
/// 设置UI图片的旋转和player的旋转一致
/// </summary>
/// <param name="quat"></param>
public void rotate(Quaternion quat)
{
ArrowRect.rotation = quat;
}
}
网友评论