KNU_SpaceShooter/Assets/02_Scripts/Barrel.cs
2024-09-12 14:33:19 +09:00

32 lines
806 B
C#

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