Skip to main content

Tilemap鼠标按下移动物体

Tilemap鼠标按下移动物体,鼠标显示图片

    /// <summary>
/// 按钮点击按下事件
/// </summary>
/// <param name="index"></param>
public void buttonClickDown(int index)
{
isFollowShow = true;
Follow.GetComponent<Image>().sprite = images[index];
Follow.SetActive(isFollowShow);
tileManage.GroundLayer.color = Color.white;
//go = GameObject.Instantiate(Follow, new Vector3(Input.mousePosition.x, Input.mousePosition.y, -1), Quaternion.identity);
}

///
//float tmp = (1 - vv) * Camera.main.orthographicSize;
//Follow.transform.localScale = new Vector3(tmp, tmp,1);

/// <summary>
/// 按钮点击抬起事件
/// </summary>
/// <param name="index"></param>
public void buttonClickUp(int index)
{
isFollowShow = false;
Follow.SetActive(isFollowShow);
Vector3Int gridPos = tileManage.GetGridPos();
tileManage.CreateGoods(gridPos, index); // 创建物体
tileManage.GroundLayer.color = Color.clear;
}

发现UGUI的图片不会随摄像机的放大缩小改变。

解决方法:

加了一个浮动层(tilemap),不断生成删除,松开鼠标隐藏浮动层。