Need help with logic problem (JavaScript)

Hello,

I have been working with code all day and it burns me out so this is probably something small and/or simple that I am missing. I have two scripts that I am using in this problem of mine, a “CharacterDamage” script that keeps track of my player and enemies health and a “PlayerSmoke” script that show how damaged the player’s vehicle is (instead of a health bar). Both scripts have no compile errors so I can still play the game but the PlayerSmoke script isn’t doing what I want it too. I want the player’s vehicle (which is the player themself actually) to start producing smoke at certain Empty GameObject’s postions attached to the vehicle. I have the smoke particles and gameObjects in place already but when I take damage down to the certain health points, no smoke spawns. Here is the “CharacterDamage” Script(which I am sure is fine) that I am accessing from the “PlayerSmoke” Script:

#pragma strict


var hp : float;
var replacementSpawn : GameObject[];
var replacement : GameObject[];


//Take Damage Function
//Subtract damage from hp

function TakeDamage( damage : float )
{
	hp = hp - damage;
	if(hp <= 0)
	{

		var i : float = 0;
		
		while( i < replacementSpawn.Length)
		{
			var y : float = 0;
			while( y < replacement.Length)
			{
				replacementSpawn *= Instantiate(replacement[y], transform.position, transform.rotation);*
  •  		yield WaitForSeconds (0.09);*
    
  •  		y++;*
    
  •  	}*
    
  •  	i++;*
    
  •  }*
    
  •  	Destroy(gameObject);*
    
  • }*

}
And here is the “PlayerSmoke” script (which Im sure has the Logical error):
#pragma strict

var player : GameObject;
var characterDamage : CharacterDamage;
var lightSmokePrefab : GameObject;
var lightSmokeSpawnOne : GameObject;
var lightSmokeSpawnTwo : GameObject;
var moderateSmokePrefab : GameObject;
var moderateSmokeSpawn : GameObject;
var heavySmokePrefab : GameObject;
var heavySmokeSpawn : GameObject;

function Start()
{

  • characterDamage = player.GetComponent(CharacterDamage);*
    }

function TakeDamage( damage : float )
{

  • characterDamage.hp = characterDamage.hp - damage;*
  • if(characterDamage.hp <= 80)*
  • {*
  •  Instantiate(lightSmokePrefab, lightSmokeSpawnOne.transform.position, lightSmokeSpawnOne.transform.rotation);*
    
  • }*
  • else if(characterDamage.hp <= 60)*
  • {*
  •  Instantiate(lightSmokePrefab, lightSmokeSpawnTwo.transform.position, lightSmokeSpawnTwo.transform.rotation);*
    
  • }*
  • else if(characterDamage.hp <= 40)*
  • {*
  •  Instantiate(moderateSmokePrefab, moderateSmokeSpawn.transform.position, moderateSmokeSpawn.transform.rotation);*
    
  • }*
  • else if(characterDamage.hp <= 20)*
  • {*
  •  Instantiate(heavySmokePrefab, heavySmokeSpawn.transform.position, heavySmokeSpawn.transform.rotation);*
    
  • }*
    }
    The “TakeDamage” function is from my Damage script but I also am sure that one has no problems. Thanks for looking at my question and a reply would be much appreciated.

Replace your PlayerSmoke script’s TakeDamage method with this and see what the console says (I have a feeling you don’t call the method):

function TakeDamage( damage : float )
{
    Debug.Log("PlayerSmoke.TakeDamage() has been called");

    if(characterDamage == null)
        Debug.Log("characterDamage object is null!!");

    if(lightSmokeSpawnOne == null)
        Debug.Log("lightSmokeSpawnOne object is null!!");

    if(lightSmokeSpawnTwo == null)
        Debug.Log("characterDamage object is null!!");

    if(moderateSmokeSpawn == null)
        Debug.Log("moderateSmokeSpawn object is null!!");

    if(heavySmokeSpawn == null)
        Debug.Log("heavySmokeSpawn object is null!!");

    if(lightSmokePrefab== null)
        Debug.Log("lightSmokePrefab object is null!!");

    if(moderateSmokePrefab == null)
        Debug.Log("moderateSmokePrefabobject is null!!");

    if(heavySmokePrefab== null)
        Debug.Log("heavySmokePrefabobject is null!!");

    characterDamage.hp = characterDamage.hp - damage;
    if(characterDamage.hp <= 80)
    {
        Instantiate(lightSmokePrefab, lightSmokeSpawnOne.transform.position, lightSmokeSpawnOne.transform.rotation);
        Debug.Log("smoke created for hp: " + characterDamage.hp);
    }
    else if(characterDamage.hp <= 60)
    {
        Instantiate(lightSmokePrefab, lightSmokeSpawnTwo.transform.position, lightSmokeSpawnTwo.transform.rotation);
        Debug.Log("smoke created for hp: " + characterDamage.hp);
    }
    else if(characterDamage.hp <= 40)
    {
        Instantiate(moderateSmokePrefab, moderateSmokeSpawn.transform.position, moderateSmokeSpawn.transform.rotation);
        Debug.Log("smoke created for hp: " + characterDamage.hp);
    }
    else if(characterDamage.hp <= 20)
    {
        Instantiate(heavySmokePrefab, heavySmokeSpawn.transform.position, heavySmokeSpawn.transform.rotation);
        Debug.Log("smoke created for hp: " + characterDamage.hp);
    }
}