Page 435 - MDP2022-3
P. 435

다.  게임  엔딩  및  재시작





















            클리어  화면                                          게임오버  화면  및  재시작버튼



             using  System.Collections;
             using  System.Collections.Generic;
             using  UnityEngine;


             public  class  GameOverCanvas  :  MonoBehaviour
             {
                     public  static  GameOverCanvas  instance  =  null;
                     public  GameObject  player;
                     public  GameObject  subCamera;
                     public  GameObject  gameoverposition;


                     private  void  Awake()
                     {
                             if  (instance  ==  null)  //instance가  null.  즉,  시스템상에  존재하고  있지  않을때
                             {
                                     instance  =  this;  //내자신을  instance로  넣어줍니다.
                                     DontDestroyOnLoad(gameObject);  //OnLoad(씬이  로드  되었을때)  자신을  파괴하지  않고  유지
                             }
                             else
                             {
                                     if  (instance  !=  this)  //instance가  내가  아니라면  이미  instance가  하나  존재하고  있다는  의미
                                             Destroy(this.gameObject);  //둘  이상  존재하면  안되는  객체이니  방금  AWake된  자신을  삭제
                             }
                     }
                     public  void  die()
                     {
                             Debug.Log("die");
                             subCamera.SetActive(false);
                             player.SetActive(true);
                             player.transform.position  =  gameoverposition.transform.position;
                     }
             }
   430   431   432   433   434   435   436   437   438   439   440