Hello,
I am making a games mechanic which is a bit like Pokemon, in that there are a list of moves, and each character has 4 that they can use. Each moves needs to do a certain amount of damage, cost a certain amount of mana, and have a string that has its name.
They way I am doing it right now is with a script that contains all the moves, as their own function, like:
public void Tackle() {
damage = 10;
mana = 10;
Debug.Log("Tackle");
}
Now, this is working fine, as I run this, and take damage away from the enemies health in the other script, and mana away from maxMana in the other script too. But I can’t figure out how to make it so that the player can choose the moves for the character, and how I will make it so that the button holds a variable with the move, instead of what I am doing right now, which is just running certain moves as default.
Perfectly happy for suggestion that require me to redo the whole battle system. I just really need to find a way to do this, and to learn a bit about saving progress and that kinda stuff. One of the parts of scripting in Unity that I’m very new to.
Thanks,
Danny
P.S. If you script in Javascript and not in C#, the logic of how to do this would still be fantastic 
The code you have up right now doesn’t seem very reusable. What if you want to change the damage later on as the player increases levels? What if they don’t know tackle anymore? Etc.
Just off the top of my head I would probably have like my four buttons. And they will read the script from whoever is attacking to draw in the info for what they should say. So read in the name of the attack and display it on top of your button. The next thing that would happen is when you click the button it will attack the enemy by reading how much damage to inflict on the opponent. It would also know how much mana to take away from the attacker. You can make this happen by using a function maybe called attack1, attack2, attack3, attack4 which would pass arguments like
attack1(int damage, int mana,…) so then all the button has to do is execute
attack1(damage, mana, ...) {
get the enemys health and apply "damage"
get the players mana bar and reduce their mana
and maybe at this point after all your battle stuff has finished then you can switch it to the opponent to allow their attack
or whatever else is happening
}[CODE]
But you want to think about reusability. How can you write your game so you can keep using your code over and over again.
Hope this helped you out. Take a minute to write down your game. See where you are going to use things multiple times and
try to figure out with psuedocode how you will actually write the game. Break it apart piece by piece.
One last idea, maybe an array of arrays that will hold your attack info. ["Tackle", 10, 10, 0] where ["name of attack", attackDamage, manaUse, recoilDamage] etc. Stop and think, don't just rush into your code.
This is the way I tried doing it first, but I couldn’t for the life of me figure out how to reference it in another script. I’m guessing this would be a good, reusable way of doing it though, right? Could have a multiplier based on the level that is multiplied by the damage to get the level scaling:
public class Stats {
public int damage;
public int manaCost;
public string name;
}
public void Start() {
Stats Move1 = new Stats();
Stats Move2 = new Stats();
Stats Move3 = new Stats();
Stats Move4 = new Stats();
Move1.name = "Tackle";
Move1.damage = 5;
Move1.manaCost = 5;
}
Thanks a lot for the help, means a lot.