Replace if ladders with switches and enums, shop easier to edit
This commit is contained in:
@@ -2,7 +2,7 @@ using UnityEngine;
|
||||
|
||||
public class GameState : MonoBehaviour
|
||||
{
|
||||
public string state;
|
||||
public State state;
|
||||
public uint wave;
|
||||
public GameObject ratbot;
|
||||
public GameObject shop;
|
||||
@@ -10,15 +10,22 @@ public class GameState : MonoBehaviour
|
||||
OpenShop();
|
||||
}
|
||||
|
||||
public enum State {
|
||||
Wave,
|
||||
Shop,
|
||||
Menu,
|
||||
Paused,
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (GameObject.FindGameObjectsWithTag("Ratbot").Length == 0 && state == "WAVE") {
|
||||
if (GameObject.FindGameObjectsWithTag("Ratbot").Length == 0 && state == State.Wave) {
|
||||
OpenShop();
|
||||
}
|
||||
}
|
||||
void OpenShop() {
|
||||
state = "SHOP";
|
||||
state = State.Shop;
|
||||
Instantiate(shop);
|
||||
}
|
||||
public void NewWave() {
|
||||
@@ -26,7 +33,7 @@ public class GameState : MonoBehaviour
|
||||
Destroy(GameObject.FindGameObjectWithTag("Shop"));
|
||||
// Spawn ratbots around the player
|
||||
// Amount, health, and damage scale with waves
|
||||
state = "WAVE";
|
||||
state = State.Wave;
|
||||
Vector3 playerPosition = GameObject.FindGameObjectWithTag("Player").transform.position;
|
||||
for (uint _ = 0; _ <= wave; _++) {
|
||||
GameObject newRatbot = Instantiate(
|
||||
|
||||
@@ -548,7 +548,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: attackCooldown
|
||||
upgrade: 3
|
||||
amount: -0.5
|
||||
--- !u!1 &2887698150694367543
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -833,7 +834,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: attackRange
|
||||
upgrade: 0
|
||||
amount: 1
|
||||
--- !u!1 &3627401992951871319
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -968,7 +970,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: maxHealth
|
||||
upgrade: 4
|
||||
amount: 20
|
||||
--- !u!1 &4009611485654107892
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1103,7 +1106,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: attackDistance
|
||||
upgrade: 1
|
||||
amount: 1
|
||||
--- !u!1 &4405246042370862087
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1376,7 +1380,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: movementSpeed
|
||||
upgrade: 5
|
||||
amount: 5
|
||||
--- !u!1 &4600683873005582980
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1511,7 +1516,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: attackDamage
|
||||
upgrade: 2
|
||||
amount: 5
|
||||
--- !u!1 &4791604686138271717
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1646,7 +1652,8 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: dashDistance
|
||||
upgrade: 6
|
||||
amount: 1
|
||||
--- !u!1 &5832695598238337749
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -2304,4 +2311,5 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a8661788ccc10d9fd9d1c9c2019bf2d3, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
upgrade: dashCooldown
|
||||
upgrade: 7
|
||||
amount: -0.5
|
||||
|
||||
@@ -2,41 +2,49 @@ using UnityEngine;
|
||||
|
||||
public class ShopButton : MonoBehaviour
|
||||
{
|
||||
public string upgrade;
|
||||
public UpgradeOption upgrade;
|
||||
public float amount;
|
||||
public enum UpgradeOption {
|
||||
AttackRange,
|
||||
AttackDistance,
|
||||
AttackDamage,
|
||||
AttackCooldown,
|
||||
MaxHealth,
|
||||
MovementSpeed,
|
||||
DashDistance,
|
||||
DashCooldown
|
||||
}
|
||||
void Start() {
|
||||
GetComponent<UnityEngine.UI.Button>().onClick.AddListener(Upgrade);
|
||||
}
|
||||
void Upgrade() {
|
||||
Teo player = GameObject.FindGameObjectWithTag("Player").GetComponent<Teo>();
|
||||
GameState gameState =
|
||||
GameObject
|
||||
.FindGameObjectWithTag("GameController")
|
||||
.GetComponent<GameState>();
|
||||
if (upgrade == "attackRange") {
|
||||
player.swingRange += 1;
|
||||
switch (upgrade) {
|
||||
case UpgradeOption.AttackRange:
|
||||
player.swingRange += amount;
|
||||
break;
|
||||
case UpgradeOption.AttackDistance:
|
||||
player.swingDistance += amount;
|
||||
break;
|
||||
case UpgradeOption.AttackDamage:
|
||||
player.damageStrength += amount;
|
||||
break;
|
||||
case UpgradeOption.AttackCooldown:
|
||||
player.attackCooldownSeconds += amount;
|
||||
break;
|
||||
case UpgradeOption.MaxHealth:
|
||||
player.health += amount;
|
||||
player.maxHealth += amount;
|
||||
break;
|
||||
case UpgradeOption.MovementSpeed:
|
||||
player.moveSpeed += amount;
|
||||
break;
|
||||
case UpgradeOption.DashDistance:
|
||||
player.dashDistance += amount;
|
||||
break;
|
||||
case UpgradeOption.DashCooldown:
|
||||
player.dashCooldownSeconds += amount;
|
||||
break;
|
||||
}
|
||||
else if (upgrade == "attackDistance") {
|
||||
player.swingDistance += 0.5F;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,19 @@ TextureImporter:
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 4
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
ignorePlatformSupport: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites:
|
||||
@@ -134,7 +147,8 @@ TextureImporter:
|
||||
secondaryTextures: []
|
||||
spriteCustomMetadata:
|
||||
entries: []
|
||||
nameFileIdTable: {}
|
||||
nameFileIdTable:
|
||||
rangeIndicator_0: -3951105813050061920
|
||||
mipmapLimitGroupName:
|
||||
pSDRemoveMatte: 0
|
||||
userData:
|
||||
|
||||
Reference in New Issue
Block a user