untiy3d 实时更新UI上小地图的图片旋转与玩家一致

更新UI上image的旋转与transform的旋转一致

using UnityEngine;
using System.Collections;

[AddComponentMenu("MiniMap/Map arrow")]
public class MapArrow : MonoBehaviour
{

    private RectTransform ArrowRect;

    void Awake()
    {
        ArrowRect = transform.GetComponent();
    }

    public Transform playerTransform;
    private bool rotateMap;
    void Update()
    {
        if (rotateMap)
        {
            rotate(Quaternion.identity);
        }
        else
        {
            rotate(Quaternion.Euler(new Vector3(0, 0, -playerTransform.eulerAngles.y)));
        }
    }
    /// 
    /// 设置UI图片的旋转和player的旋转一致
    /// 
    /// 
    public void rotate(Quaternion quat)
    {
        ArrowRect.rotation = quat;
    }

}

你可能感兴趣的:(untiy3d 实时更新UI上小地图的图片旋转与玩家一致)