Search Unity

Suggestions for doing scripts for RPG items

Discussion in 'Scripting' started by Not_Sure, Nov 21, 2019.

  1. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,546
    I'm thinking of creating a script that has every single possible effect on it.

    Needless to say that seems unnecessarily complex.

    So maybe make a script that makes the item and attaches different effect scripts?

    If there are any good links to tutorials I would really appreciate it.

    Thanks!
     
  2. Serinx

    Serinx

    Joined:
    Mar 31, 2014
    Posts:
    788
    I'd do something like this.

    Have an "ItemEffect" abstract base class with methods "Activate" "Tick" and "Deactivate"

    Create child classes that inherit "ItemEffect" and override those methods so they can all do different things.

    Your Items could then have a script with a List of ItemEffects and you can add each of the effects you want the item to have.
    The item script could activate the effects whenever you want e.g. Weapons activate on hit, potions activate when drunk
    It could also loop through the ItemEffects and call the Tick() method in a coroutine.

    Each item would work differently, e.g. you might have an amulet item with a "PassiveHealingEffect" that adds 1hp to the player's health every Tick, and a potion with a "BerserkerEffect" that increases strength when Activate is called, then reduces HP when Deactivate is called.

    There are a lot of different ways to do it. It really depends on the type of effects you want your items to have, but abstracting it out to those 3 basic methods should cover quite a few bases.
     
    Not_Sure likes this.