Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Need advice implementing replaceable spell system th

Discussion in 'Scripting' started by INDAX, Jun 25, 2019.

  1. INDAX

    INDAX

    Joined:
    Jun 29, 2014
    Posts:
    6
    I am building a game that player can freely choose a few spell into the battlefield.
    I read a post about implementing a basic replaceable spell system: here

    The problem I'm still having is that, some of the spells need to reference properties of its caster.
    That is, some of the spells will have different effects depending on the current state of the caster.
    Some of the spell might be more powerful when having lower hp or having faster speed etc.

    If I implement the spells in separate prefabs, wouldn't it be inefficient to reference to spell's parent's script everytime caster casts a spell?
    Is there any better way to implement such a system?

    Any advice would be appreciated!
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    ScriptableObjects for storing data and switching.

    Pass your caster as a parameter to your ".Cast()" method, do with the caster anything you want.
     
  3. INDAX

    INDAX

    Joined:
    Jun 29, 2014
    Posts:
    6
    Thanks for the advice! That's a smart way to do it. I'll try it out.