Hello, I am a new Unity programmer and I'm just starting to use my first events. I have a controller script, that plays some animations using coroutines. I have two sliders on the scene and a slider script attached to both. It is my understanding these two scripts are completely seperate instances. Both sliders have "On value changed" function assigned, using different functions on the class...sliderOne(), sliderTwo(). These methods call the events like this:
public class SliderScript : MonoBehaviour
{
[SerializeField] public ControllerScript controller;
public static event Action ActionCompleteOne;
public static event Action ActionCompleteTwo;
// Update is called once per frame
public void ChangeOne(float value)
{
if (value > 0f && value <= .05f){
if (TunerComplete != null) // new
ActionCompleteOne();
}
}
}
I am now trying to use the controller to add events to ActionCompleteOne. What I'm not understanding is variable scope for these class objects. I followed a bunch of guides and they simply have me assign it as if the class was available. If this is correct, I don't get how it is available...
public class ControllerScript : MonoBehaviour
{
public ExampleScript exampleController;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
SliderScript.ActionCompleteOne += AnimationContinue;
StartCoroutine(AnimationStart());
}
private IEnumerator AnimationStart()
{
// animation runs
}
private void AnimationContinue()
{
}
}