I’m wanting to be able to set off grenades with explosions and for whatever reason it’s not getting set off.
This is the code that I have on the grenade:
private void OnCollisionEnter(Collision collision){
if (collision.gameObject.tag == "Enemy" || collision.gameObject.tag == "Shot") {
Explode();
}
}
It blows up when it touches an enemy AND when I shoot it directly with a projectile.
But for whatever reason it completely ignores explosions.
Here’s a script for one of those said explosions:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rocket_Impact : MonoBehaviour {
public AudioSource soundImpact;
public float lifeTime;
public float lifeClock;
public float force;
public int damage;
SphereCollider myCollider;
// Use this for initialization
void Awake()
{
transform.GetComponent<SphereCollider>().enabled = true;
}
void OnEnable()
{
lifeClock = lifeTime;
transform.GetComponent<SphereCollider>().enabled = true;
}
// Update is called once per frame
void Update()
{
if (lifeClock > 0)
{
lifeClock -= Time.deltaTime;
if (lifeClock <= 0)
{
gameObject.SetActive(false);
}
}
}
private void FixedUpdate()
{
bool skipFrame = true;
if (skipFrame == false) transform.GetComponent<SphereCollider>().enabled = false;
if (skipFrame == true) skipFrame = false;
}
void OnTriggerEnter(Collider hit)
{
Vector3 vectorForce = force * (hit.transform.position - transform.position);
hit.transform.gameObject.GetComponent<Rigidbody>().AddForce(vectorForce);
if (hit.CompareTag("Player"))
{
//Debug.Log("You shot yer self!");
hit.transform.gameObject.GetComponent<Status>().ChangeCurrentHealth(damage);
hit.transform.gameObject.GetComponent<Rigidbody_Controller>().movementToggle = true;
}
if (hit.CompareTag("Enemy"))
{
//Debug.Log("SPLASH!");
hit.transform.gameObject.GetComponent<Enemy_Stats>().ChangeHealth(damage);
return;
}
}
}
And the REALLY nutty part is that it sends the grenade soaring from the addforce, but does not explode.
And, of course, I made sure that everything has the “Shot” tag.
Any ideas why it’s not blowing up?