2024-09-11 17:40:04 +09:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class RemoveBullet : MonoBehaviour
|
|
|
|
{
|
2024-09-12 14:02:37 +09:00
|
|
|
[SerializeField] private GameObject sparkEffect;
|
|
|
|
|
2024-09-12 14:06:40 +09:00
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
sparkEffect = Resources.Load<GameObject>("SparksEffect");
|
|
|
|
}
|
|
|
|
|
2024-09-11 17:40:04 +09:00
|
|
|
void OnCollisionEnter(Collision coll)
|
|
|
|
{
|
2024-09-12 13:05:56 +09:00
|
|
|
// Garbage Collection
|
|
|
|
// if (coll.collider.tag == "BULLET")
|
|
|
|
if (coll.collider.CompareTag("BULLET"))
|
2024-09-11 17:40:04 +09:00
|
|
|
{
|
|
|
|
Destroy(coll.gameObject);
|
2024-09-12 14:16:06 +09:00
|
|
|
|
|
|
|
// 충돌 정보
|
|
|
|
ContactPoint cp = coll.GetContact(0);
|
|
|
|
// 충돌 지점(좌표)
|
|
|
|
Vector3 pos = cp.point;
|
|
|
|
// 충돌 지점의 법선 벡터
|
|
|
|
Vector3 normal = -cp.normal;
|
|
|
|
// 벡터를 Quaternion 타입으로 변환
|
|
|
|
Quaternion rot = Quaternion.LookRotation(normal);
|
|
|
|
|
|
|
|
// 스파크 생성
|
|
|
|
Instantiate(sparkEffect, pos, rot);
|
2024-09-11 17:40:04 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 충돌 콜백함수
|
|
|
|
/*
|
|
|
|
# Collider의 Is Trigger 언체크
|
|
|
|
|
|
|
|
OnCollisionEnter --- 1
|
|
|
|
OnCollisionStay --- n
|
|
|
|
OnCollisionExit --- 1
|
|
|
|
|
|
|
|
|
|
|
|
# Collider의 Is Trigger 체크
|
|
|
|
|
|
|
|
OnTriggerEnter --- 1
|
|
|
|
OnTriggerStay --- n
|
|
|
|
OnTriggerExit --- 1
|
|
|
|
|
|
|
|
*/
|
|
|
|
}
|