実装しようとしたこと
今回、Time.deltaTimeを利用し、敵の体力が0になった時に、進行中のdeltaTimeに値を加算してあげる。というのを組みました。
問題点
以下のスクリプトを記載したところ、敵を倒していくごとに、
5 10 15 20・・・
と敵ごとに与えたAddTime数分加算されていくという現象になってしまいました。
解決したいこと
この加算されていく現象を無くし、そのオブジェクトに与えられた数分だけ上昇するようにしたい。
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class Enemy : MonoBehaviour { 6 7 public int HP = 5; 8 public static int Enemy_HP; 9 10 public float speed; 11 public float AddTime; 12 public static float ADDTIME; 13 14 15 public static Enemy enemy_instance; 16 17 // Use this for initialization 18 void Start () { 19 20 21 enemy_instance = this; 22 } 23 24 // Update is called once per frame 25 void Update () { 26 27 ADDTIME = AddTime; 28 Enemy_HP = HP; 29 30 31 32 if (HP <= 0) 33 { 34 GameManager.GameTimerUPFlg = true; 35 36 Debug.Log("truw"); 37 38 GameManager.GameTimerDelta += AddTime; 39 AddTime = 0; 40 41 Destroy(gameObject); 42 43 44 } 45 46 } 47 48 49} 50
c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5 6public class GameManager : MonoBehaviour { 7 8 //遷移先誘導変数 9 public string gameover= "GameOver"; 10 11 //ゲーム進行時間設定用変数 12 public static float GameTimerDelta; 13 public bool AddTimerFlg; 14 public float GameTimer; 15 public Text GameTimerText; 16 public float GameDecrementParametor; 17 public static bool GameTimerUPFlg; 18 19 private Text text; 20 21 // Use this for initialization 22 void Start () { 23 24 this.text= GetComponent<Text>(); 25 } 26 27 // Update is called once per frame 28 void Update() 29 { 30 GameTimerText.text = GameTimer.ToString("0"); 31 32 Main(); 33 } 34 private void Main() 35 { 36 //ゲーム進行時間 37 GameTimer -= Time.deltaTime; 38 //敵撃破字時に時間を増加 39 if (GameTimerUPFlg) 40 { 41 GameTimerUPFlg = false; 42 GameTimer += GameTimerDelta; 43 } 44 45 } 46} 47

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。