From 3a2ee12182eba1254bf3ca912f3d119c147cc5fb Mon Sep 17 00:00:00 2001 From: Anonymous Raccoon <32224410+AnonymusRaccoon@users.noreply.github.com> Date: Mon, 13 Aug 2018 16:22:33 +0200 Subject: [PATCH] Adding tree power. --- Assets/Scenes/SampleScene.unity | 4 +-- Assets/Script/InventoryManager.cs | 52 ++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index 9d46024..0241759 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.37311992, g: 0.38074034, b: 0.35872713, a: 1} + m_IndirectSpecularColor: {r: 0.37311953, g: 0.38074014, b: 0.3587274, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -13478,7 +13478,7 @@ MonoBehaviour: - {fileID: 11400000, guid: 479a6c0ea55dd864aa07a48020a25d5d, type: 2} - {fileID: 0} canOverrideTree: 0 - canBePlacedOn: 2 + canBePlacedOn: 3 count: 0 - type: 0 description: diff --git a/Assets/Script/InventoryManager.cs b/Assets/Script/InventoryManager.cs index 43f0102..da400e3 100644 --- a/Assets/Script/InventoryManager.cs +++ b/Assets/Script/InventoryManager.cs @@ -103,13 +103,6 @@ public class InventoryManager : MonoBehaviour } } - //Spawn Power - switch (item.type) - { - default: - break; - } - CallOtherPowers(); } @@ -128,16 +121,25 @@ public class InventoryManager : MonoBehaviour } } - //Spawn Power - switch (item.type) - { - default: - break; - } - //CallOtherPowers(); } + private void DeleteTreeAt(int index) + { + Vector2Int plotPos = GetPlotPositionByIndex(index); + plots[index].treePlaced = TreeType.Nothing; + + int i = 0; + for (int y = 0; y > -4; y--) + { + for (int x = 0; x < 4; x++) + { + treeMap.SetTile(new Vector3Int(plotPos.x * 4 + x, plotPos.y * 4 + y, 0), null); + i++; + } + } + } + private async void CallOtherPowers() { List dontCallPlotPower = new List(); @@ -169,6 +171,28 @@ public class InventoryManager : MonoBehaviour await Task.Delay(1000); } } + else if(plots[i].treePlaced == TreeType.ThirstyTree) + { + List plot = new List(); + + if (i - 1 >= 0 && i % 5 != 0 && plots[i - 1].treePlaced == TreeType.Cactus) + plot.Add(i - 1); + if (i + 1 <= 24 && i % 5 != 4 && plots[i + 1].treePlaced == TreeType.Cactus) + plot.Add(i + 1); + if (i - 5 >= 0 && plots[i - 5].treePlaced == TreeType.Cactus) + plot.Add(i - 5); + if (i + 5 <= 24 && plots[i + 5].treePlaced == TreeType.Cactus) + plot.Add(i + 5); + + if(plot.Count > 0) + { + int r = Random.Range(0, plot.Count); + dontCallPlotPower.Add(plot[r]); + DeleteTreeAt(i); + PlaceTree(items[(int)TreeType.Cactus - 1], plot[r]); + await Task.Delay(1000); + } + } } }