Script with the event:
public class SplashScene : MonoBehaviour {
//variables set...
void Start () {
//...
Finish += someDebug;
}
IEnumerator fadeInMethod(float fadeTime, Color colorStart, Color colorEnd) {
//...
Debug.Log("Here we are");
if(Finish != null)
Finish ();
}
public delegate void MethodPointer();
public event MethodPointer Finish;
void someDebug() {
Debug.Log ("This is some debug");
}
}
Other GameObject script:
void Start () {
loadedScene = 0;
scenesScript = new SplashScene[scenes.Length];
sceneObject = new GameObject[scenes.Length];
for (int i = 0; i < scenes.Length; ++i) {
sceneObject _= GameObject.Instantiate (scenes *);*_
_ sceneObject .SetActive (false);
scenesScript = scenes .GetComponent (typeof(SplashScene)) as SplashScene;
* }*_
* sceneObject [0].SetActive (true);*
* scenesScript [0].Finish += Next;*
* Debug.Log ("Some data: " + scenesScript [0].duration);*
* }*
* void Next() {*
* Debug.Log (“Hello”);*
* sceneObject [loadedScene].SetActive (false);*
* Destroy (sceneObject [loadedScene]);*
* ++loadedScene;*
* if (loadedScene < scenes.Length)*
* sceneObject [loadedScene].SetActive (true);*
* else {*
* //Go to a lobby*
* }*
* }*
Output:
Some data: 2;
Here we are;
This is some debug;
The question is simple: why does not work the “scenesScript [0].Finish += Next;” line?
I’ve been trying to make an Event work, but only achieved to do it by inside the own class of the class that fires it.
I do not want to change the scripts to static, i need them this way so I can learn how to use Events and Delegates in different ways and situations, but I’m stuck right now, pls help :333