Skip to content

Commit

Permalink
完善游戏停止和重启的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
moshuying committed Jul 7, 2024
1 parent 5d65bc3 commit 3f54b46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Assets/Scripts/GameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void StartGame()

// 生成人物
playerStart1 = GameObject.Find("PlayerStart1");
playerStart1.SetActive(false);
if (playerStart1 != null )
{
player = Instantiate(playerPrefab).GetComponent<PlayerController>();
Expand All @@ -51,7 +50,6 @@ public void StartGame()
player.moveSpeed = playerMovingSpeed;
}
playerStart2 = GameObject.Find("PlayerStart2");
playerStart2.SetActive(false);
if (playerStart2 != null)
{
player2 = Instantiate(playerPrefab2).GetComponent<PlayerController>();
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 3f54b46

Please sign in to comment.