using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyCollision : MonoBehaviour
{
    public int DmgFromPlayer = 100;
    public int DmgFromOther = 50;

    private IEnemy enemy;

    public void Start()
    {
        enemy = GetComponentInChildren<IEnemy>();
        if (enemy is null)
        {
            throw new ArgumentNullException(nameof(enemy));
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        var player = other.GetComponent<IPlayer>();
        if (player is object)
        {
            enemy.Health -= DmgFromPlayer;
        }
        else if (enemy is object)
        {
            // Ehm. Race condition averted. Ehm.
            enemy.Health -= DmgFromOther;
        }
    }
}
