Card Game Unique abilities run dynamically

Hi guys so this has been stumping me, so I have a card game where cards have unique abilities, now these cards are scriptable objects and some cards have unique abilities on them. Im running into an issue of how to run the ability when it needs to be triggered. I made it dynamically get the component onto the object 195904-ability.png

now i need the code to work when the condition the do is triggered but i cant explicitly hard code the name of the function in the triggering code (this is the triggering code in class "cardbehaviour)

    void Attack ()
    {
        CardTypes cardType = card.GetComponent<CardDisplay>().eCardtype;
        string cardDmg = card.transform.GetComponent<CardDisplay>().damageText.text;
        
        switch(cardType){
        case  CardTypes.BASIC:
            BattleManager.Targeting(int.Parse(cardDmg));
            break;
        
        case CardTypes.TECHNIQUE:
            executeTechnique = true;
            break;
        
        case CardTypes.PERRY:
        
             break;
        
        case  CardTypes.COUNTER:
        
             break;

        }

this is the class and code i want to have happen, but the update method im trying to use is making it do continuous damagae.

  void Update()
    {
       
        if (this.gameObject.GetComponent<CardBehaviour>().executeTechnique == true)
        {
            TechniqueExecution();
        }
    }

        public void TechniqueExecution()
        {
            CardForms cardForms = BattleManager.activePlayer.FormCard.GetComponent<CardDisplay>().eCardForm;

            if (cardForms == this.gameObject.GetComponent<CardDisplay>().eCardForm)
            {
                
                CrecentCannon();
                
            }
            else
            {
                this.gameObject.GetComponent<CardBehaviour>().executeTechnique = false;
                CresecntKickStandard();
                
            }
        }

I think you need to look at using a UnityEvent this allows you to add multiple functions in the inspector and call them, so you don’t need the name

I have a similar scenario where I want to be able to run different events when the player collides with Triggers, but I don’t want to have to create separate scripts each time. So I use UnityEvents attached to the gameobject and I can assign as many or as few actions as I want in the inspector with no additional coding

 public UnityEvent FunctionsToCall;

That will give you the below, so just like a UI Button event
195915-unityevent.jpg

You can then drag in any scripts onto that and assign the commands you want to run

To call all the events use

FunctionsToCall.Invoke();

You should be able to create a card, add the functionstoacall script assign all the events you want to run and invoking the events from your other script when you called “ExecuteTechnique” This should allow for the same call on all cards but allow you to set different functions on each card. Therefore not needing the name of the function you want to call.

Just a couple of other points,

  1. you should create a reference to the CardBehaviour, calling GetComponent every update is expensive, just add it to your Start routine
  2. I think it’s calling multiple times because you only set executeTechnique back to false in the else section so it can call CrecentCannon everyframe

What I normally do to make sure something in the Update Method is running once, is add a boolean like “alreadyDamaged”, setting it to false at the start, and then making it true just after the code required is run.

In your case,

     if (this.gameObject.GetComponent<CardBehaviour>().executeTechnique == true && alreadyDamaged == false)
     {
         TechniqueExecution();
          alreadyDamaged = true;
     }

I am just a beginner, so if this is not what you are looking for… do tell