Skip to content

develop GameOver

Jeon-YJ1004 edited this page Mar 3, 2023 · 5 revisions

Game Over Panel

  1. 캐릭터의 체력이 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에 판넬 생성

image

2.2 판넬에 text와 button 생성, button에 text 생성
image

2.3 button 클릭시 결과 씬으로 이동하는 함수 호출
image

  1. GameResultScene 생성 후 File>Build Settings에 씬 추가
    image

Game Result Scene

image image

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);
          
    }
   

image

Clone this wiki locally