Hey guys, I’m having a problem trying to access an Enemy variable for the RPG we’re working on, basically what’s going on is that when the player chooses attack, the script looks for the EnemyName object provided by the enemy collider’s parent.
After that a string variable called EnemyBattleCode takes the enemy name, and adds B_ before it so that we have the enemy battlescript’s name.
Finally, it grabs the enemy’s script and assigns it to EnemyBattleScript. All of this works just fine, the problem I’m running in to is getting the Health Variable from that script, I’m not exactly sure how to code it as adding the statement “EnemyBattleScript.Health” won’t work since it’s not grabbing it until after the game’s started and a collision has taken place, any ideas?
I’m basically trying to make it as dynamic as possible so that any other enemies we have in the future will be able to work inside of this code.
void H_Attack()
{
// This will find our Enemy GameObect that's found first inside of EnemyCollision
EnemyName = GameObject.Find(EnemyCollision.EnemyName);
//TODO Let the player chose WHO to attack.
//Creates the scriptname to find
EnemyBattleCode = "B_" + EnemyName;
// Dynamically grabs the enemy's script
EnemyBattleScript = EnemyName.GetComponent(EnemyBattleCode);
//TODO Find the Health variable inside of the newly formed EnemyBattleScript
//TODO Execute the attack.
//TODO Find out how much damage the attack did and if it's <0 for the enemy they die.
//TODO If enemy's damage is <0 the battle's over.
print("Soon to be coded for attack");
H_BattleTimer = 5;
H_BattleMessageTimer = 5;
H_BattleMessage = H_Name + " Attacked!";
H_DisplayBattleMessage = true;
}
I've been trying to mess with this for the last day, haven't been able to get it to work yet but have been trying to understand what it does. Can you explain by chance what the interface override does by chance?
– ChristmasGT