CangJie/Assets/Scripts//Interactable.cs

53 lines
1.2 KiB
C#
Raw Normal View History

using System;
2022-03-13 23:27:31 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 可交互物件基类
/// </summary>
public class Interactable : Event
{
protected Player player;
protected virtual void Start()
2022-03-13 23:27:31 +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);
}
if (other.TryGetComponent<Player>(out Player player))
{
this.player = player;
2022-03-13 23:27:31 +08:00
}
2022-03-13 23:27:31 +08:00
}
void OnTriggerExit2D(Collider2D other)
{
if (other.TryGetComponent<PlayerInteract>(out PlayerInteract playerInteract))
{
playerInteract.CancleCatched(this);
}
}
internal void OnTriggerEnter2D()
{
throw new NotImplementedException();
}
2022-03-13 23:27:31 +08:00
}