-
Notifications
You must be signed in to change notification settings - Fork 2
develop GameOver
Jeon-YJ1004 edited this page Mar 3, 2023
·
5 revisions
- 캐릭터의 체력이 0보다 작거나 같으면 GameOver가 된다. [Character.cs]
[Character.cs]
public void TakeDamage(float damage)
{
if (isDead == true) return;
currentHp -= damage;
if (currentHp <= 0)//현재 체력으로 Gameover
{
GameManager.instance.GameOverPanelUp();
isDead = true;
}
HpBar.SetState(currentHp, maxHp);
}
[GameManager.cs]
public void GameOverPanelUp()
{
Debug.Log("Game over");
player.enabled = false; // Character object 비활성화
gameoverPanel.SetActive(true); // 판넬 활성화
}
2.1 scene에 판넬 생성
2.2 판넬에 text와 button 생성, button에 text 생성
2.3 button 클릭시 결과 씬으로 이동하는 함수 호출
- GameResultScene 생성 후 File>Build Settings에 씬 추가
public class GameResult : MonoBehaviour
{
[SerializeField] TMP_Text map=null;
[SerializeField]TMP_Text time=null;
float gameTime;
[SerializeField] TMP_Text coin=null;
[SerializeField] TMP_Text level=null;
[SerializeField] TMP_Text kill =null;
Weapon weapon;
int Weaponname;
int Weaponlevel;
int Weapondamage;
int WeapondamagePerSec;
void Start()
{
level.text = string.Format("{0}",GameManager.instance.level);
kill.text =string.Format( "{0}",GameManager.instance.kill);
coin.text = string.Format("{0}",GameManager.instance.coin);
gameTime = GameManager.instance.gameTime;
float seconds = Mathf.Floor(gameTime % 60);
float minutes = Mathf.Floor(gameTime / 60);
time.text = string.Format("{0:00}:{1:00}", minutes, seconds);
}