Hi, i’m tweaking a State Machine Class that allows to work with Generics to simplify work. I’m getting an error that i can’t decode:
Assets/Scripts/Entities/Character.cs(60,33): error CS0309: The type `StateMachine<Character>' must be convertible to `UnityEngine.Component' in order to use it as parameter `T' in the generic type or method `UnityEngine.Component.GetComponent<T>()'
Here’s the code i’m using:
_stateMachine = GetComponent<StateMachine<Character>>();
And The State Machine Class format:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class StateMachine<T> where T : MonoBehaviour {
private List<State<T>> _states = new List<State<T>>();
public void onState()
{
}
public void setState(int state)
{
}
/// <summary>
/// Adds the state.
/// </summary>
/// <param name='s'>
/// a state component.
/// </param>
public void addState(State<T> s)
{
}
}
Character Class extends MonoBehaviour, so i don’t understand what it’s the nature of the problem.
Any ideas??
Thanks in advance.
Francisco.