I have this script AnimalContainer:
public SheepFunctions a1;
public BirdFunctions a2;
public CowFunctions a3;
public PigFunctions a4;
void Start () {
a1 = gameObject.AddComponent<SheepFunctions>();
a2 = gameObject.AddComponent<BirdFunctions>();
a3 = gameObject.AddComponent<CowFunctions>();
a4 = gameObject.AddComponent<PigFunctions>();
}
//ANIMAL 1
public void Animal1Shape()
{
a1.ChangeShape();
}
public void Animal1Update()
{
a1.UpdateFunctions();
}
public void Animal1Ability()
{
a1.Ability();
}
These are the circumstances I want for level1 (scene 1).
In level2 I would like the public variables and the Start() content to be changed to the following:
public FoxFunctions a1;
public TurtleFunctions a2;
public DinoFunctions a3;
public HorseFunctions a4;
void Start () {
a1 = gameObject.AddComponent<FoxFunctions>();
a2 = gameObject.AddComponent<TurtleFunctions>();
a3 = gameObject.AddComponent<DinoFunctions>();
a4 = gameObject.AddComponent<HorseFunctions>();
}
Also, I can’t just make another script for each level. Because this class is loaded from the PlyaerController, like this:
ac = gameObject.AddComponent<AnimalContainer>();
How can I solve my problem, when I can’t make “if-statements” at the variable declaration section? Been speculating all day now!
EDIT: Is it possible to convert a type, such as C# class into another C# class, because that might do it. Something like:
a4 = a4 as HorseFunctions;
I know this doesn’t work, it says, Cannot convert type PigFunctions' to
SheepFunctions’ via a built-in conversion. But I hope you get the idea?