var maxDist : float = 1000000000;
var decalHitWall : GameObject;
var floatInFrontOfWall : float = 0.00001;
var damage : float = 100;
var bulletForce : float = 1000;
function Update ()
{
var hit : RaycastHit;
if (Physics.Raycast(transform.position, transform.forward, hit))
{
if (decalHitWall && hit.transform.tag == "Level Parts")
Instantiate(decalHitWall, hit.point + (hit.normal * floatInFrontOfWall), Quaternion.LookRotation(hit.normal));
if (hit.transform.tag == "Enemy")
{
Debug.Log("hit enemy");
hit.transform.SendMessage("ApplyDamage", damage);
}
}
Destroy(gameObject);
}
My Bullet script sends a message to the enemy that is hit…
var startingHealth = 100;
private var enemyHealth : int;
function Start () {
enemyHealth = startingHealth;
}
function ApplyDamage(damage : int) {
Debug.Log("taking hit");
enemyHealth -= damage;
if (enemyHealth <= 0) {
Destroy (gameObject);
}
}
The ApplyDamage function is successfully called. The issue however is that enemyHealth does not change??? This script is attached to the enemy which is tagged ‘Enemy’.
Debug logs show that it should be working:
hit enemy
UnityEngine.Debug:Log(Object)
BulletScript:Update() (at Assets/Scripts/BulletScript.js:16)
taking hit
UnityEngine.Debug:Log(Object)
EnemyHealth:ApplyDamage(Int32) (at Assets/Scripts/EnemyHealth.js:9)
UnityEngine.Component:SendMessage(String, Object)
BulletScript:Update() (at Assets/Scripts/BulletScript.js:17)
What am I missing? This was working in another scene.