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

https://codegenius.org/open/courses/19/sections/61Unity FAQ

爆発のエフェクトを発生させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
// ★追加
// エフェクトプレハブのデータを入れるための箱を作る。
public 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);
}
}
}


BattleTank(基礎/全31回)
他のコースを見る
https://codegenius.org/open/courses/19/sections/61Unity FAQ

爆発のエフェクトを発生させる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyObject : MonoBehaviour
{
// ★追加
// エフェクトプレハブのデータを入れるための箱を作る。
public 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);
}
}
}


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