Okay I've been trying to create a script that applies damage to rigid bodies through an explosion radius but the message I'm trying to send to another script doesn't seem to be sending. I'm not getting any error messages or anything the only thing I can think of is the the message has no where to go or the message is receiving but not applying. the action of actual force is working fine though.
This is the script I have so far.
using UnityEngine;
using System.Collections;
public class Grenade : MonoBehaviour {
public float radius = 5.0f,
power = 10.0f,
explosiveLift = 1.0f,
explosiveDelay = 5.0f;
void Update (){
explosiveDelay -= Time.deltaTime;
if (explosiveDelay <= 0){
Vector3 grenadeOrigin = transform.position;
Collider[] colliders = Physics.OverlapSphere (grenadeOrigin, radius);
foreach (Collider hit in colliders){
Rigidbody rb = hit.GetComponent();
if (rb){
rb.AddExplosionForce(power, grenadeOrigin, radius, explosiveLift);
//This is where we apply force to our enemy and various other rigid bodies
hit.SendMessageUpwards("Damager", 100, SendMessageOptions.DontRequireReceiver);
//This is where we apply damage to the enemy
Destroy(gameObject);
}
}
}
}
}
and this is my health script for my enemy
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int maxHealth = 100;
public int curHealth = 100;
// Use this for initialization
void Start () { }
// Update is called once per frame
void Update () {
if (curHealth < 1) {
Destroy (gameObject);
}
}
void OnTriggerEnter(Collider other){
if (other.gameObject.tag == "Bullet"){
curHealth -= 20;
}
}
// this is where our explosion should be inputing damage
void Damager(int curDamage){
curHealth -= curDamage;
}
}
↧