I'm facing this problem: I have three Scripts. A base class (A
), a derived class with a generic, (A<T> : A
) and another derived class B : A<T>
. So B -> A<T> -> A
.
A
has two delegates. One is called when a Coroutine finishes. The other is called when we click on the GameObject.
A
is as follows:
public class A : MonoBehaviour {
[…]
p ublic delegate int delegate_OnTimeElapsed();
public delegate_OnTimeElapsed onTimeElapsed;
public delegate void delegate_OnMouseDown(A o);
public delegate_OnMouseDown onMouseDown;
[...]
public void OnMouseDown() {
if(onMouseDown != null) onMouseDown(this);
}
[…]
protected IEnumerator LifeTime(){
[...]
if(onTimeElapsed != null) onTimeElapsed();
}
[…]
}
Now I have a Prefab with a B
Script attached that I instantiate in a Script (let's say C
) that listens to the Return key press.
C
is as follows:
[…]
public B prefab_Script; //Set in editor
public void Update(){
if(Return) {
C inst = Instantiate(prefab_Script);
inst.onTimeElapsed += Func_A;
inst.onMouseDown += Func_B;
}
}
public int Func_A(){
Debug.Log(“Time Elapsed”);
return 0;
}
public void Func_B(A o){
Debug.Log(“Mouse Down”);
}
The thing is that inside LifeTime
I get a correct reference to onTimeElapsed
but inside OnMouseDown
I see onMouseDown
as null
.
Any ideas? Thank you!!