2022-03-19 17:47:36 +08:00
|
|
|
using System;
|
2022-03-13 21:40:55 +08:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 可交互物件基类
|
|
|
|
/// </summary>
|
|
|
|
public class Interactable : Event
|
|
|
|
{
|
2022-03-19 17:47:36 +08:00
|
|
|
|
|
|
|
protected Player player;
|
|
|
|
protected virtual void Start()
|
2022-03-13 21:40:55 +08:00
|
|
|
{
|
|
|
|
//检查触发器
|
|
|
|
if (GetComponent<Collider2D>() == null)
|
|
|
|
{
|
|
|
|
Debug.LogError(this.GetType() + ": 没有碰撞盒");
|
|
|
|
}
|
|
|
|
else if(GetComponent<Collider2D>().isTrigger == false)
|
|
|
|
{
|
|
|
|
Debug.LogError(this.GetType() + ": 碰撞盒没有设置为触发器");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerEnter2D(Collider2D other)
|
|
|
|
{
|
|
|
|
if (other.TryGetComponent<PlayerInteract>(out PlayerInteract playerInteract))
|
|
|
|
{
|
|
|
|
playerInteract.SetCatched(this);
|
2022-03-19 17:47:36 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
if (other.TryGetComponent<Player>(out Player player))
|
|
|
|
{
|
|
|
|
this.player = player;
|
2022-03-13 21:40:55 +08:00
|
|
|
}
|
2022-03-19 17:47:36 +08:00
|
|
|
|
2022-03-13 21:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D other)
|
|
|
|
{
|
|
|
|
if (other.TryGetComponent<PlayerInteract>(out PlayerInteract playerInteract))
|
|
|
|
{
|
|
|
|
playerInteract.CancleCatched(this);
|
|
|
|
}
|
|
|
|
}
|
2022-03-19 17:47:36 +08:00
|
|
|
|
|
|
|
internal void OnTriggerEnter2D()
|
|
|
|
{
|
|
|
|
throw new NotImplementedException();
|
|
|
|
}
|
2022-03-13 21:40:55 +08:00
|
|
|
}
|