unity3D技术分享Unity教程合集

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

2017-04-14  本文已影响162人  好怕怕

更新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;
    }

}

上一篇下一篇

猜你喜欢

热点阅读