- Home /
Problem Setting Data Onto Another Script
I have two scripts, the script that contains all of my gui's called MyGUI and my EnemyAI
When an enemies curHealth (a variable) equals zero it should make the character's AttackXP = a number (another variable in a different script)
I have this variable in side of EnemyAI
public static MyGUI mg;
I do also have all the other variables needed for what im making... Inside of EnemyAI i also have this
if(curHealth == 0)
mg.AttackXP += GiveXP;
}
When the enemies curHelath equals zero it doesn't give the xp to the AttackXP which is in MyGUI.
I dont know what wrong at the moment and all help is appreciated.
Answer by Jessy · Jan 15, 2011 at 01:42 AM
Are you clamping curHealth to zero? My first thought is that you have it going past zero, into the negatives, so it's never equal to zero.
Otherwise, is curHealth a float? If so, try Mathf.Approximately instead of the == operator.
Just let us know if it's ever actually zero; Debug.Log it and watch the Console.
right, and do you set your static reference to your GUI script? btw. such a reference should be inside your $$anonymous$$yGUI script. You can use it everywhere in any script you like with: $$anonymous$$yGUI.mg that's more natural. Normally such static vars are named "instance"