生成物体片段
曾经使用世界坐标点生成物体,结果被tilemap
覆盖了
// 屏幕坐标 转 世界坐标
Vector3 wordPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//Debug.LogError(wordPos);
// 世界坐标 转 格子坐标
Vector3Int callPos = GoodsLayer.WorldToCell(wordPos);
//// 格子坐标 转 世界坐标
Vector3 createPostion = GoodsLayer.CellToWorld(callPos);
//2d检测 鼠标下的物体
Ray myRay = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.Log(myRay);
//RaycastHit2D hit = Physics2D.Raycast(new Vector2(myRay.origin.x, myRay.origin.y), Vector2.down,2);
RaycastHit2D hit = Physics2D.Raycast(new Vector2(createPostion.x, createPostion.y), Vector2.down, 2);
Debug.Log(hit);
Debug.Log(hit.collider);
if (hit.collider != null)
{
//do something print (hit.collider);
Debug.Log("2d物体名称:" + hit.collider.name);
}
else
{
GoodsLayer.SetTile(callPos, tile);
//GoodsLayer.BoxFill(callPos, tile,0,0,5,5);
//tilemap.RefreshAllTiles();
//GoodsLayer.RefreshAllTiles();
//GameObject.Find("Grid/Goods").transform
//GameObject.Instantiate(goods, new Vector3(createPostion.x, createPostion.y, -1), Quaternion.identity);
}