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 e5ed225 commit 399c6f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
18 changes: 13 additions & 5 deletions Assets/Scripts/GameMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public void StartGame()
}
isGameRunning = true;

if (player)
{
player.gameObject.SetActive(false);
GameObject.Destroy(player.gameObject);
}
if (player2)
{
player2.gameObject.SetActive(false);
GameObject.Destroy(player2.gameObject);
}

// 生成人物
playerStart1 = GameObject.Find("PlayerStart1");
if (playerStart1 != null )
Expand Down Expand Up @@ -96,11 +107,8 @@ public void StopGame()

// 控制 UI Panel
uiController.EnterEndPanel();

player.gameObject.SetActive(false);
GameObject.Destroy(player.gameObject);
player2.gameObject.SetActive(false);
GameObject.Destroy(player2.gameObject);
player.disableInput();
player2.disableInput();
}

public void EndGame()
Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ void endGame()
{
GameObject.Find("GameMode").GetComponent<GameMode>().StopGame();
}
private bool disableUserInput = false;
public void disableInput()
{
disableUserInput = true;
}

void Update()
{
if (disableUserInput)
{
return;
}
//GROUNDED
if (Physics.Raycast(transform.position + new Vector3(0.1f, 0.1f, 0.1f), Vector3.down, 0.15f)
|| Physics.Raycast(transform.position + new Vector3(0.1f, 0.1f, -0.1f), Vector3.down, 0.15f)
Expand Down

0 comments on commit 399c6f1

Please sign in to comment.