マイロボットにライフタイムを設定する











ライフタイム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 追加(忘れずに!)
using UnityEngine.UI;
public class LifeTimer : MonoBehaviour
{
    public float botLifeTime;
    public GameObject effectPrefab;
    public AudioClip sound;
    private Slider timeSlider;
    void Start()
    {
        timeSlider = GetComponent<Slider>();
        timeSlider.maxValue = botLifeTime;
        timeSlider.value = botLifeTime;
    }
    void Update()
    {
        botLifeTime -= Time.deltaTime;
        timeSlider.value = botLifeTime;
        if(botLifeTime <= 0)
        {
            GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
            Destroy(effect, 0.5f);
            AudioSource.PlayClipAtPoint(sound, transform.position);
            Destroy(transform.root.gameObject);
        }
    }
}

【2019版】TowerD I(基礎/全10回)
| 1 | 敵ロボットの作成&前進 | 
| 2 | 敵ロボットをターンさせる1 | 
| 3 | 敵ロボットをターンさせる2 | 
| 4 | 敵ロボットにHPをつける | 
| 5 | ロボットを生み出す装置を作る | 
| 6 | マイロボットの作成1 | 
| 7 | マイロボットにライフタイムを設定する | 
| 8 | マイロボットの作成2 | 
| 9 | ★チェックポイント | 
| 10 | ★チャレンジ | 











ライフタイム
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 追加(忘れずに!)
using UnityEngine.UI;
public class LifeTimer : MonoBehaviour
{
    public float botLifeTime;
    public GameObject effectPrefab;
    public AudioClip sound;
    private Slider timeSlider;
    void Start()
    {
        timeSlider = GetComponent<Slider>();
        timeSlider.maxValue = botLifeTime;
        timeSlider.value = botLifeTime;
    }
    void Update()
    {
        botLifeTime -= Time.deltaTime;
        timeSlider.value = botLifeTime;
        if(botLifeTime <= 0)
        {
            GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
            Destroy(effect, 0.5f);
            AudioSource.PlayClipAtPoint(sound, transform.position);
            Destroy(transform.root.gameObject);
        }
    }
}

マイロボットにライフタイムを設定する