- Home /
Question by
SUpersindit2 · Mar 09, 2015 at 08:34 AM ·
interfaces
Implenting a simple Interfaces Correctly?
Creating:
public interface IKillAble
{
void Kill();
}
Implenting:
using UnityEngine;
using System.Collections;
public class PlayerStats : MonoBehaviour,IKillAble
{
private float health;
void Update()
{
Debug.Log (health);
Kill(); //i use this to implent the interface am i doing it correctly?
}
public void Kill()
{
health -= 1f;
}
}
Comment
Best Answer
Answer by NoseKills · Mar 09, 2015 at 08:36 AM
If it doesn't give you a compiler error, you are implementing it correctly. Since your interface defines void Kill(); and you have implemented public void Kill(); you have implemented the interface.
When and where you call Kill(); has nothing to do with the interface.
Your answer