Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to implement status effects in a turn based battle.

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

  1. MikawasakiDigital

    MikawasakiDigital

    Joined:
    Mar 29, 2019
    Posts:
    95
    Hey guys, I've been building a turn based battle system but I've found myself stumped on the addition of a statues effect system. Would anyone have any insight to offer on the best way to code this thing? Any insight offered is appreciated, and feel free to ask for the code if you need it from my end.
     
  2. ZombieTFK

    ZombieTFK

    Joined:
    Sep 6, 2016
    Posts:
    55
    Really depends on a lot of variables here. The most flexible, and my preferred method would be to use an event based approach, but it's kind of involved.

    Most straight forward approach would be to make something along the lines of a
    Status
    abstract class or
    ITickable
    interface. After that, make a
    StatusCollection
    class that extends MonoBehaviour (It's basically a wrapper for a
    List<Status>
    /
    List<ITickable>
    ), now add the StatusCollection script to your prefab, and just do something along the lines of
    MyGameObject.GetComponent<StatusCollection>().AddStatus(MyStatus);
    . So applying the effect in a turn manager for example might look like
    MyGameObject.GetComponent<StatusCollection>().TickAllStatusEffects();
    .
     
    MikawasakiDigital likes this.
  3. MikawasakiDigital

    MikawasakiDigital

    Joined:
    Mar 29, 2019
    Posts:
    95
    Thanks brother, list looks perfect actually. Do you have a tutorial or something I can follow along to help me implement this? If not I'l try to figure it out, and thank you so much anyways.