2024-09-12 14:23:26 +09:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class Barrel : MonoBehaviour
|
|
|
|
{
|
|
|
|
private GameObject expEffect;
|
2024-09-12 14:26:13 +09:00
|
|
|
private int hitCount = 0;
|
2024-09-12 14:23:26 +09:00
|
|
|
|
|
|
|
void Start()
|
|
|
|
{
|
2024-09-12 14:23:59 +09:00
|
|
|
expEffect = Resources.Load<GameObject>("BigExplosion");
|
2024-09-12 14:23:26 +09:00
|
|
|
}
|
|
|
|
|
2024-09-12 14:26:13 +09:00
|
|
|
void OnCollisionEnter(Collision coll)
|
2024-09-12 14:23:26 +09:00
|
|
|
{
|
2024-09-12 14:26:13 +09:00
|
|
|
if (coll.collider.CompareTag("BULLET"))
|
|
|
|
{
|
|
|
|
if (++hitCount == 3)
|
|
|
|
{
|
2024-09-12 14:30:07 +09:00
|
|
|
Instantiate(expEffect, transform.position, Quaternion.identity);
|
|
|
|
var rb = this.gameObject.AddComponent<Rigidbody>();
|
2024-09-12 14:33:19 +09:00
|
|
|
|
|
|
|
// 랜덤한 좌표값을 계산
|
|
|
|
Vector3 pos = transform.position + Random.insideUnitSphere;
|
|
|
|
|
|
|
|
rb.AddExplosionForce(1500.0f, pos, 10.0f, 1800.0f);
|
2024-09-12 14:26:13 +09:00
|
|
|
}
|
|
|
|
}
|
2024-09-12 14:23:26 +09:00
|
|
|
}
|
|
|
|
}
|