I am trying to use a system of base and derived classes in Unity for the first time.
What I can’t figure out is how I can show instance variables in the inspector, if that is possible at all. Possibly I’m doing this completely wrong from the start. My intention was to set up a system where I can have spells derive from the base class and build on them, and then use a script on the player to instantiate these attacks. So I don’t need an entire, almost duplicate, script for each attack.
I need them in the inspector so that I can assign prefabs for, for example, particle systems that are specific to each attack.
This is the beginning that I’ve made:
using UnityEngine;
using System.Collections;
public class AttacksHandler : MonoBehaviour
{
GameObject playerGO;
public class Spell
{
public bool needsTarget;
public float movementSpeed;
public int damage;
public GameObject attackVisual; //HOW TO SHOW THIS THING IN INSPECTOR FOR EACH INSTANCE?
public Spell(bool _needsTarget, float _movementSpeed, int _damage)
{
needsTarget = _needsTarget;
movementSpeed = _movementSpeed;
damage = _damage;
}
}
public class Fireball : Spell
{
public ParticleSystem explosionEffect; //HOW TO SHOW THIS THING IN INSPECTOR FOR EACH INSTANCE?
GameObject target;
public Fireball(bool _needsTarget, float _movementSpeed, int _damage) :
base(_needsTarget, _movementSpeed, _damage)
{
}
}
public Fireball redFireball = new Fireball(true, 50f, 25);
public Fireball greenFireball = new Fireball(false, 20f, 200);
void Start()
{
playerGO = GameObject.FindGameObjectWithTag("Player");
}
}
Again, I may be doing this completely wrong alltogether but this was my idea to use OOP.