game: trying to fix score/day/customercount system

This commit is contained in:
kookiekenobi 2025-02-03 03:49:50 +08:00
parent 66ccb98f61
commit 049109cb80
4 changed files with 38 additions and 24 deletions

View file

@ -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

View file

@ -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<NPCMovement>();
npcBehaviourScript = npcObject.GetComponent<NPCBehaviour>();
playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
}
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();
}
}
}

View file

@ -12,19 +12,18 @@ using UnityEngine;
public class Despawn : MonoBehaviour
{
private Player playerScript;
/// <summary>
/// Destroy NPC object on trigger enter
/// </summary>
/// <param name="other"></param>
public void OnTriggerEnter(Collider other)
{
/*Debug.Log(other.name);*/
if (other.CompareTag("NPC"))
{
other.gameObject.SetActive(false);
Destroy(other.gameObject);
/*Debug.Log("NPC left");*/
}
}

View file

@ -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<GameManager>();
}
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);
}
}
}