From 049109cb80fe5326204cd02d6263b88b5ef79b00 Mon Sep 17 00:00:00 2001 From: kookiekenobi Date: Mon, 3 Feb 2025 03:49:50 +0800 Subject: [PATCH] game: trying to fix score/day/customercount system --- SSLR/Assets/Scenes/LiviPlayground.unity | 35 +++++++++++++++---------- SSLR/Assets/Scripts/DeskButtons.cs | 9 +++++++ SSLR/Assets/Scripts/Despawn.cs | 5 ++-- SSLR/Assets/Scripts/Player.cs | 13 +++++---- 4 files changed, 38 insertions(+), 24 deletions(-) diff --git a/SSLR/Assets/Scenes/LiviPlayground.unity b/SSLR/Assets/Scenes/LiviPlayground.unity index fcb5ab6..11f6563 100644 --- a/SSLR/Assets/Scenes/LiviPlayground.unity +++ b/SSLR/Assets/Scenes/LiviPlayground.unity @@ -819,8 +819,28 @@ PrefabInstance: m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: [] - m_AddedComponents: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 1717954561962503725, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3} + insertIndex: -1 + addedObject: {fileID: 456355250} m_SourcePrefab: {fileID: 100100000, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3} +--- !u!1 &456355243 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 1717954561962503725, guid: f6336ac4ac8b4d34bc5072418cdc62a0, type: 3} + m_PrefabInstance: {fileID: 441087506} + m_PrefabAsset: {fileID: 0} +--- !u!114 &456355250 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 456355243} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 453d520beb5656b4b8f3e696d9a97205, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &520849214 GameObject: m_ObjectHideFlags: 0 @@ -832,7 +852,6 @@ GameObject: - component: {fileID: 520849215} - component: {fileID: 520849216} - component: {fileID: 520849217} - - component: {fileID: 520849218} m_Layer: 0 m_Name: Game Manager m_TagString: Untagged @@ -881,18 +900,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: npcObject: {fileID: 624452548} ---- !u!114 &520849218 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 520849214} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 453d520beb5656b4b8f3e696d9a97205, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &624452548 GameObject: m_ObjectHideFlags: 0 diff --git a/SSLR/Assets/Scripts/DeskButtons.cs b/SSLR/Assets/Scripts/DeskButtons.cs index dc79a74..d1f2cdc 100644 --- a/SSLR/Assets/Scripts/DeskButtons.cs +++ b/SSLR/Assets/Scripts/DeskButtons.cs @@ -13,6 +13,7 @@ public class DeskButtons : MonoBehaviour { NPCMovement npcMoveScript; NPCBehaviour npcBehaviourScript; + private Player playerScript; [SerializeField] private GameObject npcObject; @@ -23,6 +24,7 @@ public class DeskButtons : MonoBehaviour { npcMoveScript = npcObject.GetComponent(); npcBehaviourScript = npcObject.GetComponent(); + playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent(); } public void DirectToLeft() @@ -57,6 +59,7 @@ public class DeskButtons : MonoBehaviour } CheckCorrectDirection(); + } void CheckCorrectDirection() @@ -64,14 +67,20 @@ public class DeskButtons : MonoBehaviour if (correctDirection == directionSent) { Player.score += 1; + Player.customersServed += 1; Debug.Log("correct"); Debug.Log(Player.score); + Debug.Log(Player.customersServed); } else { Player.score -= 1; + Player.customersServed += 1; Debug.Log("incorrect"); Debug.Log(Player.score); + Debug.Log(Player.customersServed); + + playerScript.CheckDayEnd(); } } } diff --git a/SSLR/Assets/Scripts/Despawn.cs b/SSLR/Assets/Scripts/Despawn.cs index fdc1cea..a594a4e 100644 --- a/SSLR/Assets/Scripts/Despawn.cs +++ b/SSLR/Assets/Scripts/Despawn.cs @@ -12,19 +12,18 @@ using UnityEngine; public class Despawn : MonoBehaviour { + private Player playerScript; + /// /// Destroy NPC object on trigger enter /// /// public void OnTriggerEnter(Collider other) { - /*Debug.Log(other.name);*/ - if (other.CompareTag("NPC")) { other.gameObject.SetActive(false); Destroy(other.gameObject); - /*Debug.Log("NPC left");*/ } } diff --git a/SSLR/Assets/Scripts/Player.cs b/SSLR/Assets/Scripts/Player.cs index 1cd8e42..f352738 100644 --- a/SSLR/Assets/Scripts/Player.cs +++ b/SSLR/Assets/Scripts/Player.cs @@ -12,6 +12,8 @@ using UnityEngine; public class Player : MonoBehaviour { public static int score = 0; + public static int customersServed = 0; + public static int daysPlayed = 0; private GameManager gm; @@ -19,18 +21,15 @@ public class Player : MonoBehaviour { gm = GameObject.Find("Game Manager").GetComponent(); } - - void Update() - { - CheckDayEnd(); - } - void CheckDayEnd() + public void CheckDayEnd() { if (score < 0) { - Debug.Log("Game Over, Day has ended"); gm.dayEnded = true; + daysPlayed += 1; + Debug.Log("Game Over, Day has ended"); + Debug.Log(daysPlayed); } } }