I have an exploding barrel with a script that makes it explode when it is hit twice. (There is some extra code in another script for it) I want the exploding barrel to repel objects in a certain area so it’s like an actual explosion. Any help?
Explosion Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Explode : MonoBehaviour
{
public float health = 20f;
public ParticleSystem explosion;
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
StartCoroutine(explode());
}
}
IEnumerator explode()
{
explosion.Play();
var MR = gameObject.GetComponent<MeshRenderer>();
Destroy(MR);
yield return new WaitForSeconds(0.4f);
Destroy(gameObject);
}
}