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


エフェクトを出す
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);
}
}
}


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

エフェクトを出す
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);
}
}
}


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