I have a prefab Animal with attached script Animal.cs. There I'm trying to fire an event, which I want to handle in another script.
I'm trying two different approaches - and the code for that is like so:
[System.Serializable] public class _UnityEventFloat:UnityEvent<float> {}
public class Animal : MonoBehaviour
{
[SerializeField]
UnityEvent onAnimalKill;
[SerializeField]
_UnityEventFloat whenAnimalIsKilled;
...
void OnMouseDown()
{
onAnimalKill.Invoke();
whenAnimalIsKilled.Invoke(10f)
}
}
And then I have an empty global GameObject with attached script - GameController.cs. There I'm trying to catch the events fired - like this:
public class GameController : MonoBehaviour
{
...
public void OnSomeAnimalKill()
{
Debug.Log("ANIMAL WAS KILLED!!!");
}
public void OnSomeAnimalKillWithScore(float score)
{
Debug.Log("ANIMAL WAS KILLED - WITH SCORE: " + score);
}
}
However - I can't connect the two scripts. I'm trying to drag the methods from GameController on the slots of the Animal - but it doesn't work:
Any idea what I'm doing wrong? ... I guess it's something super simple - but I can't figure it out.

