- Home /
Question by
Paparakas · Nov 13, 2013 at 12:30 PM ·
eventinterfaceevent-handlingimplementation
Event is not being implemented from interface
I have an IEnemy interface
public interface IEnemy
{
event EmptyEventHandler HasDied;
}
And a class
public class CrabScript : Destructible, IEnemy {
public event EmptyEventHandler HasDied;
void Do()
{
HasDied();
}
As you can see, I implemented the IEnemy interface. I'm not sure if I implemented well, as I couldn't find anything on google on how to implement an event, so I just implemented it how all other members would be implemented. This is what I do with the member:
foreach (Component component in EnemyInstance.gameObject.GetComponents<Component>())
{
if (component is IEnemy)
{
IEnemy EnemyInstanceInterface = component as IEnemy;
EnemyInstanceInterface.HasDied += new EmptyEventHandler(OnEnemyDied);
}
}
void OnEnemyDied()
{Debug.Log("Has died");
this.EnemiesLeft--;
}
But Has Died never gets printed :(
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613121800im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
EventType.MouseDrag not working in WebPlayer 0 Answers
listen for flash events 2 Answers
Multiple OnTriggerEnter events on same Script 4 Answers
Need ICanvasRaycastFilter for physics raycasts 0 Answers
4.6 UI callback variable 1 Answer