using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpellLibrary : MonoBehaviour
{
public List<ScriptableObject> spells;
private int currentSpell = 0;
private bool scrollDone = true;
void Start()
{
Debug.Log(spells[0].GetType());
}
void Update()
{
if (Input.GetAxisRaw("Mouse Scrollwheel") == 0 && !scrollDone)
scrollDone = true;
if (Input.GetAxisRaw("Mouse Scrollwheel") != 0 && scrollDone)
{
currentSpell += (int) Input.GetAxisRaw("Mouse Scrollwheel");
if (currentSpell == spells.Count)
currentSpell = 0;
scrollDone = false;
}
if (Input.GetKeyDown(KeyCode.Mouse1))
spells[currentSpell].Cast(transform);
}
void FixedUpdate()
{
foreach (var spell in spells)
spell.GetType() x = spell;
spell.IterateCooldowns();
}
}
I’m trying to make the player only be able to use one attack type at a time but be able to cycle through which of the available attack types they’re currently using with the scroll wheel. Lists seemed like the easiest way to do this but since each of the attack types is a different scriptable object class I could only create a list with scriptable objects, not the specific classes.
However, I checked by printing spells[0].GetType() to the console and the spell (attack type) wasn’t being interpreted as a scriptable object, it was being interpreted as its scriptable object class (TestSpell in this case), but when I tried to call one of the methods that is defined in TestSpell I got a CS1061 error: “Assets\Scripts\SpellLibrary.cs(33,34): error CS1061: ‘ScriptableObject’ does not contain a definition for ‘Cast’ and no accessible extension method ‘Cast’ accepting a first argument of type ‘ScriptableObject’ could be found (are you missing a using directive or an assembly reference?)” which suggests that the spells are being interpreted as scriptable objects.
I checked by calling the method manually with a variable of type TestSpell and the error isn’t because of typos. Is there a way to ignore that error, cast the scriptable objects to what .GetType() interprets them as, or just a better way to implement this system overall?