using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class imagev : MonoBehaviour {
//场景画面
public Image go;
//人物
public GameObject player;
Vector3[] cor = new Vector3[4];
Vector3[] gocor = new Vector3[4];
//地图长宽
float a;
float b;
//场景长宽
float goa;
float gob;
//鼠标坐标与地图比例
float mouvx;
float mouvy;
// Use this for initialization
void Start () {
//获取地图四个角坐标 this就是地图
this.gameObject.GetComponent<RectTransform>().GetWorldCorners(cor);
//获取场景四个角坐标
go.GetComponent<RectTransform>().GetWorldCorners(gocor);
foreach (var item in gocor)
{
print(item);
}
//获取获取场景画面长宽
goa = gocor[2].x - gocor[0].x;
gob = gocor[1].z - gocor[0].z;
//获取地图长宽
a = cor[2].x - cor[0].x;
b = cor[1].y - cor[0].y;
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
//获取长宽比例 用鼠标坐标减去角坐标才是现在的长宽
mouvx =(Input.mousePosition.x-cor[0].x) / a;
mouvy =(Input.mousePosition.y-cor[0].y) / b;
//palyer坐标=场景长度*比例+场景角坐标
player.transform.position = new Vector3((goa * mouvx + gocor[0].x), 51, (gob * mouvy + gocor[0].z));
}
}
}