Ignore CS1061 error for list of Scriptable Objects

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?

If I’m understanding correctly, it sounds like you just need to take advantage of polymorphism by having all of your spells inherit from a base, abstract “Spell” class. The base class would contain the Cast() method, and you’d override it in the individual spell classes with each spell’s specific implementation (whether it be launching a fireball, or summoning something, etc.).
_
The base class could be as simple as this:

 public abstract class Spell : ScriptableObject
    {
        public abstract void Cast();
    }

_
And here’s an example of an actual spell that would inherit from the base class:

public class FireballSpell : Spell
{
    public override void Cast()
    {
        // Fireball-launching stuff here
    }
}

_
If you were to take that approach, the only significant change you’d need to make to the code you posted above is to change your list’s type to be Spell rather than ScriptableObject. With a list of Spells, you could then take any element from that list and perform its own unique spell-casting actions like this:

currentSpell.Cast();

_
The way polymorphism works here is that you don’t need to care about which specific spell is being cast: so long as it’s a Spell (inherits from the base class) it’s guaranteed to contain the Cast() method which is why it can be handled in a list of Spells rather than a more specific list of, say, FireballSpells or even HealingSpells or what-have-you.
_
If you’re still confused and/or don’t quite understand polymorphism, I highly recommend reading up on it and even watching a few videos about it on YouTube. It’s incredibly powerful and useful, and perfect for situations just like yours. Let me know if this helps!

I suppose that your scriptable object is defined as:

public class TestSpell : ScriptableObject

So, if your Cast method is defined inside TestSpell class, it can be only called on that class. Cast method isn’t defined in ScriptableObject, and that’s the reason CS1061 error occurs. You can fix it just by changing your list “spells” like that:

public List<TestSpell> spells;

OR, if you want to leave that list as it is, you can call Cast method like that:

(spells[currentSpell] as TestSpell).Cast(transform);