So I have a base abstract class called CurrentAnimation and two simple derived classes that inherit from it. Each derived class is attached as a script to a gameobject (FadeOutCtrl to a Fadeout gameobject and AnimationCtrl to an Animation gameobject).
The AccessTestBool method in AnimationCtrl script is invoked using a UI Button function list by referencing the Animation gameobject. So when the button is pressed the bool in its parent class turns true. However when trying to get this bool from FadeOutCtrl class, it does not return a true value. I cannot figure out why, perhaps when attaching subclass scripts to gameobjects, they each create their own instance of the parent class? The Unity documentation isn't clear on this section.
public abstract class CurrentAnimation : MonoBehaviour {
private bool testBool;
public bool TestBool // property that get's and sets testBool from outside
{
get
{
return testBool;
}
set
{
testBool = value;
}
}
protected void SetTestBool(bool current) // Stores the method's parameter value in TestBool value
{
TestBool = current;
}
}
----------
public class FadeOutCtrl: CurrentAnimation
{
private bool fadeOutBool;
private void Update()
{
fadeOutBool = TestBool; // Checking whether TestBool gets stored it in fadeOutBool or not
}
}
public class AnimationCtrl : CurrentAnimation
{
private bool animationBool;
void Update ()
{
animationBool= TestBool; //Checking whether TestBool gets stored in animationBool or not
}
public void AccessTestBool() // Accesses parent class' method and sets its parameter to true
{
SetTestBool(true);
}
}
↧