Enemy

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

//没有void Update(),因为这个只是主类。

public class Enemy : MonoBehaviour
{
    protected Animator anim;
    protected AudioSource deathAudio;
    protected Collider2D DisColl1;
    //    private float Gravity = 0;
    protected virtual void Start()
    //virtual(虚拟的)。子级能修改的。
    //单车和汽车都有轮子,但他们不是同一种车(自己理解的)
    {
        anim = GetComponent<Animator>();
        deathAudio = GetComponent<AudioSource>();
    }

    ///////////////////
    public void Death()
    {
        GetComponent<Collider2D>().enabled = false;
        //这里是直接获取2D刚体,无论是老鹰还是青蛙,直接关闭
        //不会再次二次碰撞
        Destroy(gameObject);
    }

    public void JumpOn()
    {
        //Destroy(gameObject.GetComponent<CircleCollider2D>());
        //Destroy(gameObject.GetComponent<Collider2D>());
//        DisColl1.enabled = false;
        anim.SetTrigger("death");
        deathAudio.Play();//播放死亡声音(注意按顺序)
    }
}

ozg
发布了12 篇原创文章 · 获赞 0 · 访问量 36

猜你喜欢

转载自blog.csdn.net/qq_34751660/article/details/105615031