lspdC f29c5c2a4c 4.2(已合并)
合并分支
2022-04-03 01:45:27 +08:00

43 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 进入式触发器的基类,继承自事件,每一个进入式触发器都必须继承这个类
/// </summary>
public class EntryTrigger : Event
{
private Collider2D m_collider;
public Event m_event;
public Stage m_stage;
void Start()
{
//如果没有挂载碰撞盒,则报错
if(!TryGetComponent<Collider2D>(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<Player>(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 + "没有链接事件或者演出,你确定吗?");
}
}