LitMap

作者: 醉酒青牛_fa4e | 来源:发表于2019-04-14 13:45 被阅读0次

1.取人物在大地图的比例
WidthRate= Person.pos.x/terrain.width
HeighRate=Person.pos.z/terrain.heigh

2.通过人物在大地图的比例计算出在小地图的位置
LitMapPos.x=LitMap.widthWidthRate
LitMapPos.y=LitMap.width
HeighRate
小地图的锚点要设置到左下角


//代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LitMap : MonoBehaviour {

public Transform person;

public Terrain myTerrain;

RectTransform litMapRect;
RectTransform sonRect;
float widthRate;
float heighRate;

Vector2 tmpPos = Vector2.zero;

float timer = 0;
void Start () {
     litMapRect = transform.parent.GetComponent<RectTransform>();
     sonRect = transform.GetComponent<RectTransform>();
}

void Update () {
    LitMapUpdate();

   
}

public void LitMapUpdate()
{
    timer += Time.deltaTime;
    if (timer > 0.2f)
    {
        widthRate = person.position.x / myTerrain.terrainData.size.x;
        heighRate = person.position.z / myTerrain.terrainData.size.z;
        tmpPos.x = litMapRect.sizeDelta.x * widthRate;
        tmpPos.y = litMapRect.sizeDelta.y * heighRate;
        sonRect.anchoredPosition = new Vector2(tmpPos.x, tmpPos.y);
        //旋转
        Vector3 tmpAngle = sonRect.localEulerAngles;
        tmpAngle.z = 90 - person.localEulerAngles.y;
        sonRect.localEulerAngles = tmpAngle;
    }
}

}


第二种地图:
1.人在地图中间
2.范围永远10米(固定数额)
3.小地图可以移动

这种小地图使用RawImage,通过设置


image.png

此处为要显示的图片的比例,通过它来控制显示小地图的大小


image.png
使地图移动
image.png

相关文章

  • LitMap

    1.取人物在大地图的比例WidthRate= Person.pos.x/terrain.widthHeighRat...

网友评论

      本文标题:LitMap

      本文链接:https://www.haomeiwen.com/subject/dvjrmqtx.html