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

public class Enemis : MonoBehaviour
{
protected Animator ani;
protected CircleCollider2D cl;
// Start is called before the first frame update
protected virtual void Start()
//在继承的子类中复写protected override void Start(){base.Start(); //来获取父类用到的组件}
{
ani = GetComponent();
cl = GetComponent();
}

public void Died()
{
    ani.SetTrigger("Died");
    cl.enabled = false;
}

public void D()
{
    Destroy(gameObject);
}

}

//应用-所有敌人继承Enemis
private void OnCollisionEnter2D(Collision2D collision) //(Player内代码)
{
if (collision.gameObject.tag == "Enm")
{
//Enemis eni = collision.gameObject.GetComponent();//子类对象赋给父类引用(由于各子类不同)/(通过子类获取子类中父类实例--便于调用父类方法)👌

        if (ani.GetBool("Down"))
        {
            //eni.Died();//直接调用父类中所有子类共有行为👌

            collision.gameObject.SendMessage("Died");//或者不需声明父类直接在子类中调用父类方法👍👍👍

            //collision.gameObject.transform.GetComponent<Eagle>().Died();
            //FrogRangAI frog = collision.gameObject.GetComponent<FrogRangAI>();
            //frog.Died();
//由于敌人种类不确定(Eagle,FrogRangAI),所以不能获取子类来调用父类中共有行为。🖕🖕🖕

            AddUpForce();
        }
        else if (transform.position.x < collision.gameObject.transform.position.x)
        {
            playerR.velocity = new Vector2(-3, playerR.velocity.y);
            IsHaert = true;
        }
        else if (transform.position.x > collision.gameObject.transform.position.x)
        {
            playerR.velocity = new Vector2(3, playerR.velocity.y);
            IsHaert = true;
        }
        GamePanel.Intence.Damage();
    }