目次
スクリプトを作成する
こちらを参考にスクリプトを作成して爆発させたいオブジェクトに貼り付けます
スクリプト
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ExplosionTest : MonoBehaviour { public GameObject Bomb;//爆発を呼び出す場所 public GameObject Explosion;//呼び出す爆発 // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A))//Aキーがおされたら { Instantiate(Explosion.gameObject, Bomb.transform.position, Bomb.transform.rotation);//爆発をBombの場所にBombの向きで呼び出す Destroy(Bomb.gameObject, 0.1f);//Bombを0.1秒後に消す Destroy(Explosion.gameObject, 3);//Explosionを3秒後に消す } } }
爆発するオブジェクト、呼び出す爆発を設定する
テストプレイをしてみると
Aキーがおされたら爆弾が爆発して消えました
※今回はキーがおされたら爆発にしてますが、敵に触れたらとか、何秒たったら、など好きな条件にしてみてください
爆発だけじゃなく、同じやり方で様々なエフェクトを使うこともできるので、応用してみてください
コメント