オブジェクト破壊時にエフェクト(視覚効果)をつける


エフェクトを出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
// ★追加
// エフェクトプレハブのデータを入れるための箱を作る。
[SerializeField]
private GameObject effectPrefab;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Shell"))
{
Destroy(this.gameObject);
Destroy(other.gameObject);
// ★追加
// エフェクトを実体化(インスタンス化)する。
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
// ★追加
// エフェクトを2秒後に画面から消す
Destroy(effect, 2.0f);
}
}
}


【2020版】BattleTank(基礎/全35回)
他のコースを見る

エフェクトを出す
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
// ★追加
// エフェクトプレハブのデータを入れるための箱を作る。
[SerializeField]
private GameObject effectPrefab;
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Shell"))
{
Destroy(this.gameObject);
Destroy(other.gameObject);
// ★追加
// エフェクトを実体化(インスタンス化)する。
GameObject effect = Instantiate(effectPrefab, transform.position, Quaternion.identity);
// ★追加
// エフェクトを2秒後に画面から消す
Destroy(effect, 2.0f);
}
}
}


オブジェクト破壊時にエフェクト(視覚効果)をつける