示例#1
0
 // Update is called once per frame
 void Update()
 {
     if (GameState.GameMode == GlobalGameStateManager.gameMode.battle)
     {
         if (scriptSeen)
         {
             // here we can also set triggers for things to happen after stuff is seen.. music stuff perhaps?
             if (currentScriptKey > 1000)
             {
                 // we're at the end of the script sequence
                 // todo: get out of this fight. should update any flags and ask the globalgamestatemanager to swap us back to the overworld state
                 if (hp != targetHp)
                 {
                     // wait for hp to update
                 }
                 else
                 {
                     scriptSeen = false;
                     if (hp == 1f)
                     {
                         // success, do something here
                         GameState.SetBossWon(BossIndex);
                     }
                     GameState.SetBossSeen(BossIndex);
                     GameState.BossSprites[BossIndex - 1].SetActive(false);
                     GameState.GiveItem(BossIndex);
                     GameState.GameMode = GlobalGameStateManager.gameMode.overworld;
                 }
             }
             else
             {
                 // wait for the player to pick something. for now, this is just always 1
                 if (!sentChoiceRequest)
                 {
                     ChoiceWriter.SetChoice(currentScriptKey);
                     waitingForChoice  = true;
                     sentChoiceRequest = true;
                 }
                 else
                 {
                     if (waitingForChoice)
                     {
                         // wait patiently
                     }
                     else
                     {
                         currentScriptKey *= 10;
                         currentScriptKey += playerChoice;
                         NpcWriter.SetText(currentScriptKey);
                         scriptSeen        = false; // once player has picked, we can set scriptSeen to false for the next round of text
                         sentChoiceRequest = false;
                         waitingForChoice  = false;
                         playerChoice      = 0;
                     }
                 }
             }
         }
         // hp updates
         if (hp != targetHp)
         {
             float origHp  = hp;
             float deltaHp = targetHp - hp;
             hp += Mathf.Sign(deltaHp) * hpPerSecond;
             // check for overshoot
             if (Mathf.Sign(hp - origHp) == Mathf.Sign(hp - targetHp))
             {
                 hp = targetHp;
             }
         }
         hpSlider.value = hp == 0 ? 0.01f : hp;
         //animator.SetFloat("hp", hp); // you can use this animator to set the sprite based on the hp, probably in discrete steps
     }
 }