- Home /
Question by
corlenbelspar · May 17, 2015 at 07:58 PM ·
variableinstancesingleton
How to subtract variable from singleton instance?
I've created a singleton instance called instance in my code above that UnityAnswers won't format right so I'm not going to waste anyone's time trying to put it in here.
I have the following code below and I want to subtract damage from an individual instance's health float but when the enemyDamaged function is called, it seems to subtract damage from every instance's health float. What can I change so it'll only affect the instance I called this function for?
public static void enemyDamaged (string enemy, float damage)
{
instance.sprite = GameObject.Find(enemy).GetComponent<tk2dSprite>();
SoundManager.PlaySound("hurt");
instance.shading = instance.sprite.color;
instance.health -= damage;
Debug.Log(instance.health);
instance.flashAmount = 0;
instance.rend = GameObject.Find(enemy).GetComponent<Renderer>();
if (instance.health <= 0)
{
instance.KillEnemy(GameObject.Find(enemy));
}
else
{
instance.InvokeRepeating("Flashing", 0, 0.05f);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613195808im_/https://answers.unity.com/themes/thub/images/avi.jpg)