Search Unity

Heal move JRPG // Need help with tag.

Discussion in 'Scripting' started by MikawasakiDigital, Sep 17, 2019.

  1. MikawasakiDigital

    MikawasakiDigital

    Joined:
    Mar 29, 2019
    Posts:
    95
    Hey guys, SO i'm coding a sort of turn based rpg right, now I am trying to have cure moves have a unique equation here so i'm avoid the easy way out of having them just do negative damage. So what I'm having trouble with here is...

    ...How can I call to an object that is being chosen in an instance using a tag.

    I'll explain further in some code I wrote below.

    So pretty much he, I wanna have it so when the move has the tag "Health" it performs a different equation.

    What can I do to have my code recognize something like that?

    Code (CSharp):
    1.     void DoDamage()
    2.     {
    3.         float randValue = Random.value;
    4.         if(CSM.PerformList[0].chosenAbility.f
    5.         {
    6.  
    7.         }
    8.         if (randValue < .80 - computer.currentLuck)
    9.         {
    10.             float calc_damage = computer.currentPower + CSM.PerformList[0].chosenAbility.abilityDamage;
    11.             PlayerToEngage.GetComponent<PlayerStateMachine>().TakeDamage(calc_damage);
    12.             Debug.Log("Computer Landed Hit");
    13.         }
    14.         else
    15.         {
    16.             float calc_damage = computer.currentPower + CSM.PerformList[0].chosenAbility.abilityDamage;
    17.             PlayerToEngage.GetComponent<PlayerStateMachine>().TakeDamage(calc_damage);
    18.             Debug.Log("Computer Landed Crit");
    19.         }
    20.     }
    Thanks for any insight, this community has done nothing but raise me up and inspire me to push my boundaries. Hope I can learn something with this challenge too. Resources are welcome.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Just generally speaking, since you have a method named .TakeDamage()... wouldn't you just clone that over to something that is named .TakeHealing() and call that instead?

    As far as "tags" go, I'm not sure how to answer your question. In Unity, a tag is a specific single property that is part of a GameObject. There is only a single tag on a GameObject. Nothing else in Unity has tags, but as a convenience, Components have a shortcut link called .tag that is actually a shortcut to the tag that is on the GameObject that this Component is attached to. In other words, all Components (Monobehaviors or whatever) on a GameObject all share the same tag that the GameObject does.
     
    MikawasakiDigital likes this.
  3. MikawasakiDigital

    MikawasakiDigital

    Joined:
    Mar 29, 2019
    Posts:
    95
    I see what you're saying, and I think that's a great idea. Although I guess my question here would be how can I get the game to tell the difference between which action to perform?
     
  4. MikawasakiDigital

    MikawasakiDigital

    Joined:
    Mar 29, 2019
    Posts:
    95
    Hey man just as an update, I was able to figure it out. Took some creative work but worth the effort.
     
    Kurt-Dekker likes this.