using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 进入式触发器的基类,继承自事件,每一个进入式触发器都必须继承这个类
///
public class EntryTrigger : Event
{
private Collider2D m_collider;
public Event m_event;
public Stage m_stage;
void Start()
{
//如果没有挂载碰撞盒,则报错
if(!TryGetComponent(out m_collider))
{
Debug.LogError(this.GetType() + gameObject.name + "没有挂载碰撞盒,请检查!");
}
//如果不是触发器,则报错
if(!m_collider.isTrigger)
{
Debug.LogError(this.GetType() + gameObject.name + "碰撞盒没有设置为触发器,请检查!");
}
}
virtual public void OnTriggerEnter2D(Collider2D other)
{
//如果玩家进入碰撞盒则触发事件
if(other.TryGetComponent(out Player player)) OnCall();
}
public override void OnCall()
{
//如果链接了事件或者演出,则执行
if(m_event != null) m_event.OnCall();
if(m_stage != null) m_stage.OnCall();
//如果二者都为null,则报告
if(m_event == null && m_stage == null) Debug.Log(this.GetType() + gameObject.name + "没有链接事件或者演出,你确定吗?");
}
}