Making different card effects.
I would like to make a project, sort of like Hearthstone. However, i don't know how i'd make different cards have different effects (e.g. Deal 3 damage to all minions when summoned).
It seems very bad to have a different script for EVERY card, but i don't know how i can call so many diverse functions from a single script on different prefabs.
Think of it like this, every card should have it's base properties and then has an Effect property that you extend to be all your effects, here is an example.
public class Card
{
public string Name;
public int ID;
public Effect effect;
}
Then your Effect class
public class Effect
{
public virtual void DoEffect(){}
}
Then your damage effect
public class DamageEffect : Effect
{
public int Damage;
public bool AreaEffect;
public override void DoEffect()
{
if (AreaEffect)
{
//damage all
}
}
}
Answer by Bren0831 · May 13, 2017 at 09:05 PM
You could write a script with boolean of what you wanted to do. Such as Do Damage=true or false then, get the output of the variable to activate or deactivate a part of the script. From there you could have float s on how much damage to deal. Same goes for healing. IsHeal = true or false. then a float to decide how much to heal. The code would be rather long but the end result I believe would work. Please try and if it works mark the question as answered.
Your answer
Follow this Question
Related Questions
If I call a function that is on a different script...? 1 Answer
Need help with card game logic of the cards effects. 2 Answers
Problem with custom bolts in Space Shooter 1 Answer
Instantiate not spawning at correct position 1 Answer
Sprites assigned to prefab' script' fields not assigned after launch 0 Answers