Good Day, and first thing, excuse for my low english level.
These last days i’ve been following this series of tutorials to create a “simple” Turn Based Combat System in Unity:
Everything works fine, but now I want to make the Magic system to make it a but more Dynamic.
The part of “Magic code” that I’d like to modify goes mostly like this:
- Foreach spell or skill, there’s a prefab that holds within a script, which is the spell, that receives all the variables from a “BaseAttack” Script.
- When the player selects the ability with his corresponding button, it looks for the prefab and inside it, all the info required for the skill in the script, without need of instantiating that script, and automatically takes the damage and launches it to the enemy.
Right now, the spell code is very simple:
using UnityEngine;
using System.Collections;
public class FireSpell : BaseAttack
{
public FireSpell()
{ attackName = "Fire 1";
attackDescription = "Basic Fire spell";
attackDamage = 20f;
attackCost = 10f;
}
}
As I would like it to work, at least if I’m not wrong with the logic, it should go like this:
using UnityEngine;
using System.Collections;
public class FireSpell : BaseAttack
{
private BattelStateMachine BSM;
private GameObject performer;
private HeroStateMachine HSM;
public FireSpell()
{
GameObject performer = GameObject.Find(BSM.PerformList[0].Attacker);
HeroStateMachine HSM = performer.GetComponent<HeroStateMachine>();
attackName = "Fire 1";
attackDescription = "Basic Fire spell";
attackDamage = (performer.GetComponent<BaseHero>().intellect + 20f) - BSM.PerformList[0].AttackersGameObjectTarget.GetComponent<EnemyStateMachine>().enemy.CurrDEFMag;
attackCost = 10f;
}
void Start()
{
BSM = GameObject.Find("BattleManager").GetComponent<BattelStateMachine>();
}
}
The Main problem is, as the prefab is never instantiated in the scene, the Start void, and any other void i’ve think of, isn’t able to get the gameobjects from the very moment the script is called by the button.
Do you know any way I can work around with my idea?
I am sorry if my explanations are vague or the problem is just too big, but even a simple direction would be welcome.
Thanks for the attention.