From 3f54b46d6fa54520e1a48519227429923aa0345f Mon Sep 17 00:00:00 2001 From: moshuying <1460083332@qq.com> Date: Sun, 7 Jul 2024 09:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=B8=B8=E6=88=8F=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E5=92=8C=E9=87=8D=E5=90=AF=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/GameMode.cs | 12 ++++++++---- Assets/Scripts/PlayerController.cs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/GameMode.cs b/Assets/Scripts/GameMode.cs index d985a8d..33d9931 100644 --- a/Assets/Scripts/GameMode.cs +++ b/Assets/Scripts/GameMode.cs @@ -42,7 +42,6 @@ public void StartGame() // 生成人物 playerStart1 = GameObject.Find("PlayerStart1"); - playerStart1.SetActive(false); if (playerStart1 != null ) { player = Instantiate(playerPrefab).GetComponent(); @@ -51,7 +50,6 @@ public void StartGame() player.moveSpeed = playerMovingSpeed; } playerStart2 = GameObject.Find("PlayerStart2"); - playerStart2.SetActive(false); if (playerStart2 != null) { player2 = Instantiate(playerPrefab2).GetComponent(); @@ -88,16 +86,22 @@ public void StopGame() } isGameRunning = false; - playerStart1.SetActive(false); - playerStart2.SetActive(false); if (crateSpawner != null) { crateSpawner.StopGame(); } + Debug.Log("EndGame"); + // 控制 UI Panel uiController.EnterStartPanel(); + + player.gameObject.SetActive(false); + //player + GameObject.Destroy(player.gameObject); + player2.gameObject.SetActive(false); + GameObject.Destroy(player2.gameObject); } public void EndGame() diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index b08d326..f078cd1 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -98,6 +98,18 @@ void Update() } } + + public void OnDestroy() + { + // + foreach (GameObject crate in allCarriedCrates) + { + GameObject.Destroy(crate); + } + // е + grablist.Clear(); + } + public void RemoveCrate() { GameObject crate = allCarriedCrates.Last();