I have a database script, SpellDatabase.cs which creates a number of spell objects in void Start() using the class script, Spell.cs. Each object contains various properties such as projectile force, damage, lifetime etc.
I have created projectile prefabs in Unity for each of the spells contained in the database. Each prefab has the script, ‘Projectile.cs’ attached to them. Using the Unity Inspector I want to be able to select the Spell object from SpellDatabase.cs which contains the corresponding spell properties for the projectile prefab I am working on. How do I reference SpellDatabase.cs in the Projectile.cs script so that I can achieve this?
Thanks for your reply. I’ve added a singleton pattern to my SpellDatabase script however I’m unclear how SpellDatabase.Instance can be used to allow me to select specific SpellDatabase objects from the Inspector.
My spell projectile prefabs have a Projectile.cs script and a field named ‘spellProperties’. I want to be able to assign the relevant SpellDatabase object pertaining to the spell prefab I’m working on to ‘spellProperties’ in the Inspector, e.g. when building the fire spell projectile prefab I want to be able to select the SpellDatabase object which contains the fire spell properties (SpellDatabase.Instance.fire) through the Inspector instead of having it hardcoded into unique projectile scripts for each spell prefab.
My initial post may have been difficult to follow so I’ll word it differently: How can I make the instances derived from my Spell class and created in my SpellDatabase script (e.g. Spell.fire, Spell.ice, Spell.water etc.) be displayed in a selection-styled drop-down field in the the Unity Inspector?
Hopefully that better communicates my aim. Thanks in advance.