From 4a0eee9c38b158a42de1d15f31dae2ad9b808ca3 Mon Sep 17 00:00:00 2001 From: ProtoSharkk Date: Sun, 20 Oct 2024 20:28:27 -0700 Subject: [PATCH] Made the shop upgrades work Click a shop upgrade to change its respective value and start a new wave --- Assets/GameState.cs | 10 +-- Assets/Shop/Shop.prefab | 121 +++++++++++++++++++++++++++++-- Assets/ShopButton.cs | 48 +++++++++--- Assets/Teo.cs | 4 + ProjectSettings/TagManager.asset | 1 + 5 files changed, 162 insertions(+), 22 deletions(-) diff --git a/Assets/GameState.cs b/Assets/GameState.cs index 6ee109e..4b4fbeb 100644 --- a/Assets/GameState.cs +++ b/Assets/GameState.cs @@ -3,7 +3,7 @@ using UnityEngine; public class GameState : MonoBehaviour { public string state; - public uint wave = 1; + public uint wave; public GameObject ratbot; public GameObject shop; void Start() { @@ -14,18 +14,16 @@ public class GameState : MonoBehaviour void Update() { if (GameObject.FindGameObjectsWithTag("Ratbot").Length == 0 && state == "WAVE") { - NewWave(); + OpenShop(); } } void OpenShop() { state = "SHOP"; Instantiate(shop); } - void CloseShop() { - Destroy(GameObject.FindGameObjectWithTag("Shop")); - NewWave(); - } public void NewWave() { + // Close the shop + Destroy(GameObject.FindGameObjectWithTag("Shop")); // Spawn ratbots around the player // Amount, health, and damage scale with waves state = "WAVE"; diff --git a/Assets/Shop/Shop.prefab b/Assets/Shop/Shop.prefab index 74e76d6..6739e87 100644 --- a/Assets/Shop/Shop.prefab +++ b/Assets/Shop/Shop.prefab @@ -426,6 +426,7 @@ GameObject: - component: {fileID: 3590707166687547973} - component: {fileID: 1810765289951295939} - component: {fileID: 6948310827531985872} + - component: {fileID: 8292507549941480182} m_Layer: 5 m_Name: Attack cooldown m_TagString: Untagged @@ -535,6 +536,19 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &8292507549941480182 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2210501121582206525} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: attackCooldown --- !u!1 &2887698150694367543 GameObject: m_ObjectHideFlags: 0 @@ -794,7 +808,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 9022882910902225455} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 0} + m_TargetAssemblyTypeName: + m_MethodName: + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &8976493928633758931 MonoBehaviour: m_ObjectHideFlags: 0 @@ -807,6 +833,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} m_Name: m_EditorClassIdentifier: + upgrade: attackRange --- !u!1 &3627401992951871319 GameObject: m_ObjectHideFlags: 0 @@ -819,6 +846,7 @@ GameObject: - component: {fileID: 2821706185741727598} - component: {fileID: 3110222457101526497} - component: {fileID: 8432436027514883370} + - component: {fileID: 8840007392823723187} m_Layer: 5 m_Name: MaxHealth m_TagString: Untagged @@ -928,6 +956,19 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &8840007392823723187 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3627401992951871319} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: maxHealth --- !u!1 &4009611485654107892 GameObject: m_ObjectHideFlags: 0 @@ -940,6 +981,7 @@ GameObject: - component: {fileID: 7049970464721467105} - component: {fileID: 2564473379772258309} - component: {fileID: 8138113010104631979} + - component: {fileID: 7109060488210492449} m_Layer: 5 m_Name: Attack distance m_TagString: Untagged @@ -954,7 +996,7 @@ RectTransform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4009611485654107892} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -1049,6 +1091,19 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &7109060488210492449 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4009611485654107892} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: attackDistance --- !u!1 &4405246042370862087 GameObject: m_ObjectHideFlags: 0 @@ -1199,6 +1254,7 @@ GameObject: - component: {fileID: 5981939164284974902} - component: {fileID: 890000750688743583} - component: {fileID: 5853020247942286769} + - component: {fileID: 8784410885912804585} m_Layer: 5 m_Name: MovementSpeed m_TagString: Untagged @@ -1308,6 +1364,19 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &8784410885912804585 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4542619955881930688} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: movementSpeed --- !u!1 &4600683873005582980 GameObject: m_ObjectHideFlags: 0 @@ -1320,6 +1389,7 @@ GameObject: - component: {fileID: 7340421460904404424} - component: {fileID: 6194428655250020225} - component: {fileID: 5203349972573605328} + - component: {fileID: 8977407190248410836} m_Layer: 5 m_Name: Damage m_TagString: Untagged @@ -1429,6 +1499,19 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &8977407190248410836 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4600683873005582980} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: attackDamage --- !u!1 &4791604686138271717 GameObject: m_ObjectHideFlags: 0 @@ -1441,6 +1524,7 @@ GameObject: - component: {fileID: 8928885822821693326} - component: {fileID: 5274123802509271756} - component: {fileID: 1193914752756732991} + - component: {fileID: 2689638452758117289} m_Layer: 5 m_Name: Dash distance m_TagString: Untagged @@ -1550,6 +1634,19 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &2689638452758117289 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4791604686138271717} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: dashDistance --- !u!1 &5832695598238337749 GameObject: m_ObjectHideFlags: 0 @@ -1840,7 +1937,7 @@ GameObject: - component: {fileID: 6825683250601769955} m_Layer: 5 m_Name: Shop - m_TagString: Untagged + m_TagString: Shop m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -1858,8 +1955,8 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 5071958998799822938} - - {fileID: 2509411441496476785} - {fileID: 3675853661540386651} + - {fileID: 2509411441496476785} - {fileID: 633719700537572267} - {fileID: 1980360647300492729} - {fileID: 7340970378302519037} @@ -2002,7 +2099,7 @@ MonoBehaviour: m_Calls: [] m_text: 'Movement Speed - +2' + +5' m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} @@ -2085,6 +2182,7 @@ GameObject: - component: {fileID: 1912200903467778218} - component: {fileID: 5967392686532701855} - component: {fileID: 8237118567054963905} + - component: {fileID: 2038953477076072822} m_Layer: 5 m_Name: Dash cooldown m_TagString: Untagged @@ -2194,3 +2292,16 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: [] +--- !u!114 &2038953477076072822 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7953511404242622058} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3} + m_Name: + m_EditorClassIdentifier: + upgrade: dashCooldown diff --git a/Assets/ShopButton.cs b/Assets/ShopButton.cs index a5dd02a..84e2699 100644 --- a/Assets/ShopButton.cs +++ b/Assets/ShopButton.cs @@ -2,15 +2,41 @@ using UnityEngine; public class ShopButton : MonoBehaviour { - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start() - { - - } - - // Update is called once per frame - void Update() - { - - } + public string upgrade; + void Start() { + GetComponent().onClick.AddListener(Upgrade); + } + void Upgrade() { + Teo player = GameObject.FindGameObjectWithTag("Player").GetComponent(); + GameState gameState = + GameObject + .FindGameObjectWithTag("GameController") + .GetComponent(); + if (upgrade == "attackRange") { + player.swingRange += 1; + } + else if (upgrade == "attackDistance") { + player.swingDistance += 30; + } + else if (upgrade == "attackDamage") { + player.damageStrength += 5; + } + else if (upgrade == "attackCooldown") { + player.attackCooldownSeconds -= 0.5F; + } + else if (upgrade == "maxHealth") { + player.health += 20; + player.maxHealth += 20; + } + else if (upgrade == "movementSpeed") { + player.moveSpeed += 5; + } + else if (upgrade == "dashDistance") { + player.dashDistance += 1; + } + else if (upgrade == "dashCooldown") { + player.dashCooldownSeconds -= 0.5F; + } + gameState.NewWave(); + } } diff --git a/Assets/Teo.cs b/Assets/Teo.cs index d2b6ac4..b78b58f 100644 --- a/Assets/Teo.cs +++ b/Assets/Teo.cs @@ -3,10 +3,14 @@ using UnityEngine; public class Teo : MonoBehaviour { public float health = 100; + public float maxHealth = 100; public float moveSpeed = 10; public float swingRange = 3; + public float swingDistance = 10; public float damageStrength = 10; public float attackCooldownSeconds = 2; + public float dashDistance = 5; + public float dashCooldownSeconds = 5; Rigidbody2D controller; GameState gameState; float lastAttackTime; diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 01d8beb..61903be 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -5,6 +5,7 @@ TagManager: serializedVersion: 3 tags: - Ratbot + - Shop layers: - Default - TransparentFX