public void SelectPlaceBuilding(BuildingsProfile profile) { if (currentPlaceBuilding != null) { DeleteGhost(); } // отображение здание перед постройкой и просчет его позиций currentPlaceBuilding = profile; spriteRenderer.enabled = true; spriteRenderer.sprite = profile.Icon; Vector3 sizeRadius = Vector3.zero; sizeRadius.x = profile.activeRadius; sizeRadius.y = profile.activeRadius; sizeRadius.z = 1; activeRadius.localScale = sizeRadius; float offsetX = profile.size.x / 2 - 0.5f; float offsetY = profile.size.y / 2 - 0.5f; for (int x = 0; x < profile.size.x; x++) { for (int y = 0; y < profile.size.y; y++) { Vector2 newPos = regionToPlace.position; newPos.x += offsetX - x; newPos.y += offsetY - y; PlacePrefab cube = PoolManager.GetObject(0, newPos, Quaternion.identity).GetComponent <PlacePrefab>(); cube.transform.SetParent(regionToPlace); placeBlocks.Add(cube); } } }
private void DeleteGhost() { currentPlaceBuilding = null; spriteRenderer.enabled = false; activeRadius.localScale = Vector3.forward; foreach (var block in placeBlocks) { block.GetComponent <PoolObject>().ReturnToPool(); } }
public void Present(BuildingsProfile profile) { icon.sprite = profile.Icon; price.text = profile.Price.ToString(); button.onClick.AddListener(() => { if (GoldManager.instance.Gold >= profile.Price) { GoldManager.instance.Gold -= profile.Price; PlaceLogic.instance.SelectPlaceBuilding(profile); } }); }