スコアアタック用のカウント
テキストを配置
スクリプトを用意
Level直下にスクリプト用意してみる
↑で配置したテキストオブジェクトをセットしておく
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CountTimer : MonoBehaviour{ public float CountDownTime; //カウントスタート値 public Text TextCountDown; //テキストオブジェクト設定用 void Start(){ CountDownTime = 60.0f; //スタート値設定 } void Update(){ TextCountDown.text = CountDownTime.ToString("f3"); //f3 = 小数3位まで表示 CountDownTime -= Time.deltaTime; //カウントダウン //0.0以下になった時処理 if(CountDownTime <= 0.0f){ CountDownTime = 0.0f; } } }
カウントダウン値を敵を倒した時に取得してスコアを変動させたい
早く倒せば得点が高くなるみたいな
Health_Enemy.csを改造すれば良いかも
まずは変数を追加
private GameObject countDownObject; //CountTimerオブジェクトを入れる用 CountTimer countTimer; //CountTimerスクリプトを入れる用 private int addTimeScore; //intにcastしたもの入れる用
得点発生部分で加算してあげる
if (PointsWhenDestroyed != 0){ countDownObject = GameObject.Find("CountTimer"); //CountTimerを検索して取得 countTimer = countDownObject.GetComponent<CountTimer>(); //↑のオブジェクトからCountTimerスクリプト取得 addTimeScore = (int)countTimer.CountDownTime; //↑のスクリプト内の変数CountDownTimeをintにcast //トドメ攻撃の判定 if(hitObjectName == "PlayerWeapon2(Clone)DamageArea (UnityEngine.GameObject)"){ meleeScore = meleeScore + addTimeScore; //破壊時にボーナススコアを加算 CorgiEnginePointsEvent.Trigger(PointsMethods.Add, meleeScore); }else{ shotScore = shotScore + addTimeScore; //破壊時にボーナススコアを加算 CorgiEnginePointsEvent.Trigger(PointsMethods.Add, shotScore); } }
なんとか基本は出来た
youtu.be
射撃攻撃で倒すと今まで10点なんだけど、カウントダウンの数値が加算されてます