I want to do something like this:
private IAnimalFunctions a1; //This is a class
string animal = PlayerPrefs.GetString ("animal1") + "Functions";
a1 = gameObject.AddComponent(animal);
Gives following error: error CS0266: Cannot implicitly convert type UnityEngine.Component' to
IAnimalFunctions’. An explicit conversion exists (are you missing a cast?)
But it works if I write it like this:
a1 = gameObject.AddComponent<SheepFunctions>();
The animal string’s value is equal to “SheepFunctions”. Is this possible, if so - how?