マイロボットにライフタイムを設定する
ライフタイム
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);
}
}
}
ライフタイム
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);
}
}
}
マイロボットにライフタイムを設定する