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

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,143评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,276评论 4 61
  • 关注的公众号前日推送了一篇文章(原文链接:如何用5K的工资招到10K的员工?),对其中谈到招聘工作的思路拓展,以及...
    无聊小事阅读 398评论 1 2
  • 转自:http://www.cnblogs.com/TenosDoIt/p/3453089.html#b 一 概述...
    碧影江白阅读 1,597评论 1 2
  • Tasty Type Tips(美味类型提示) Over hundreds of years, classic t...
    41d132813f64阅读 185评论 0 0