コード例 #1
0
 void Update()
 {
     if (!stormHasStarted && deathByFall)
     {
         fallingTimer -= Time.deltaTime;
         float newScale = fallingTimer / INITIALFALLINGTIMER;
         player.transform.localScale = new Vector3(newScale, newScale, newScale);
         if (fallingTimer < 0)
         {
             stormHasStarted = true;
         }
     }
     if (currentStormTimer > 0 && stormHasStarted)
     {
         if (!deathByFall)
         {
             currentStormTimer -= Time.deltaTime;
         }
         else
         {
             currentStormTimer -= Time.deltaTime * (initialStormTimer / 4);
         }
         if (currentStormTimer < initialStormTimer / 2)
         {
             stormImage.color = new Color(deathByFall ? 0 : 1, deathByFall ? 0 : 1, deathByFall ? 0 : 1, 1 - currentStormTimer / (initialStormTimer / 10));
         }
     }
     else if (!runningOutOfTime && stormHasStarted)
     {
         runningOutOfTime = true;
         TriggerGameOver();
     }
     if (runningOutOfTime && !gameOverIsDisplayed)
     {
         if (gameOverIsFadingIn)
         {
             currentGameOverApparitionTimer -= Time.deltaTime;
             Color gameOverTextColor = gameOverTextMesh.color;
             gameOverTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 1 - currentGameOverApparitionTimer / INITIALGAMEOVERAPPARITIONTIMER);
             if (currentGameOverApparitionTimer < 0)
             {
                 gameOverIsDisplayed = true;
             }
         }
         else
         {
             currentGameOverWaitTimer -= Time.deltaTime;
             if (currentGameOverWaitTimer < 0)
             {
                 gameOverIsFadingIn = true;
             }
         }
     }
     if (gameOverIsDisplayed && !gameOverRestartIsDisplayed)
     {
         if (gameOverRestartIsFadingIn)
         {
             currentGamerOverRestartApparitionTimer -= Time.deltaTime;
             Color gameOverTextColor = gameOverTextMesh.color;
             gameOverRestartTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 1 - currentGamerOverRestartApparitionTimer / INITIALGAMEOVERRESTARTAPPARITIONTIMER);
             if (currentGamerOverRestartApparitionTimer < 0)
             {
                 gameOverRestartIsDisplayed = true;
             }
         }
         else
         {
             currentGamerOverRestartWaitTimer -= Time.deltaTime;
             if (currentGamerOverRestartWaitTimer < 0)
             {
                 gameOverRestartIsFadingIn = true;
             }
         }
     }
     if (gameOverIsFadingIn && Input.GetButtonDown("Pickup"))
     {
         // TODO : Replace the scene loading with the correct behaviour to restart the night
         deathByFall = false;
         player.transform.localScale = new Vector3(1, 1, 1);
         player.GetComponent <Rigidbody2D>().constraints = RigidbodyConstraints2D.FreezeRotation;
         if (DayNightManager.GetDay())
         {
             Scene scene = SceneManager.GetActiveScene();
             SceneManager.LoadScene(scene.name);
         }
         else
         {
             player.transform.position  = GetComponent <PictureBehaviour>().GetPlayerNightInitialPosition();
             stormHasStarted            = false;
             runningOutOfTime           = false;
             currentStormTimer          = initialStormTimer;
             gameOverIsFadingIn         = false;
             gameOverIsDisplayed        = false;
             gameOverRestartIsFadingIn  = false;
             gameOverRestartIsDisplayed = false;
             stormImage.color           = new Color(1f, 1f, 1f, 0f);
             Color gameOverTextColor = gameOverTextMesh.color;
             gameOverTextMesh.color        = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 0);
             gameOverRestartTextMesh.color = new Color(gameOverTextColor.r, gameOverTextColor.g, gameOverTextColor.b, 0);
             DayNightManager.ChangeCycle();
             StartStorm();
         }
     }
 }