Asset Store에서 원하는 폭발 이펙트를 검색하여 Import 한다.
추가하였다면 Prefabs폴더에 추가하고 한번만 폭발하도록 Script를 추가한다.
충돌하였을 때 폭발 하도록 충돌 이벤트에 폭발 이펙트를 생성시켜준다.
1 2 3 4 5 6 7 8 9 10 11 | public class DestroyAtTime : MonoBehaviour { public float Time = 0.5f; // Start is called before the first frame update void Start() { //Time 후 Object 삭제 Destroy(gameObject, Time); } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | public class EnemyControl : MonoBehaviour { public float Speed = 50.0f; private Transform myTransform = null; //폭발 Object public GameObject Explosion = null; // Start is called before the first frame update void Start() { myTransform = GetComponent<Transform>(); } // Update is called once per frame void Update() { Vector3 moveAmount = Speed * Vector3.back * Time.deltaTime; myTransform.Translate(moveAmount); if(myTransform.position.y <= -60.0f) { InitPosition(); } } /// <summary> /// 위치 초기화 /// </summary> void InitPosition() { myTransform.position = new Vector3(Random.Range(-60.0f, 60.0f), 60.0f, 0.0f); } //충돌 이벤트 함수 void OnTriggerEnter(Collider other) { if(other.tag == "Bullet") { Debug.Log("Bullet Trigger Enter"); //폭발 Object 생성 Instantiate(Explosion, myTransform.position, Quaternion.identity); InitPosition(); Destroy(other.gameObject); } } } | cs |
'유니티' 카테고리의 다른 글
[유니티] 사운드 삽입 (0) | 2019.03.13 |
---|---|
[유니티] Object 충돌 (0) | 2019.03.08 |
[유니티] Random 위치에 Object 이동 (0) | 2019.03.07 |
[유니티] Object 생성 (0) | 2019.03.05 |
[유니티]Object 삭제 (0) | 2019.03.04 |