コード例 #1
0
 //IVulnerable Functions
 //See IVulnerable.cs
 public static void Injure(IVulnerable target, float amount)
 {
     target.Health -= amount;
     if (target.Health <= 0)
     {
         target.Kill();
     }
 }
コード例 #2
0
    //When the spikes detect a collision, it attempts to exectute the target's Kill method.
    //If the target is not an IVulnerable object, the script does nothing.
    private void OnCollisionEnter2D(Collision2D collision)
    {
        IVulnerable target = collision.gameObject.GetComponent("IVulnerable") as IVulnerable;

        if (target != null)
        {
            target.Kill();
        }
    }