// Update is called once per frame void Update() { Vector3 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); worldPoint = new Vector3(Mathf.Floor(worldPoint.x), Mathf.Floor(worldPoint.y), -1); this.transform.position = worldPoint + new Vector3(0.5f, 0.5f, 0); Vector3Int floorPosition = TilemapManager.instance.floorTilemap.WorldToCell(worldPoint); GameObject floor = TilemapManager.instance.floorTilemap.GetInstantiatedObject(floorPosition); Vector3Int wallPosition = TilemapManager.instance.wallTilemap.WorldToCell(worldPoint); GameObject wall = TilemapManager.instance.wallTilemap.GetInstantiatedObject(wallPosition); if (buildingType.CanBuildHere(floor, wall)) { spriteRenderer.color = buildColor; if (Input.GetMouseButtonDown(0)) { TilemapManager.instance.wallTilemap.SetTile(wallPosition, buildingType.tileType); BuildingBase newBuilding = TilemapManager.instance.wallTilemap.GetInstantiatedObject(wallPosition).GetComponent <BuildingBase>(); DestroySelf(); } } else { spriteRenderer.color = noBuildColor; } if (Input.GetMouseButtonDown(1)) { DestroySelf(); } }