religion/Assets/Scripts/Interactive.cs

38 lines
1.1 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 可交互物体基类
/// </summary>
public class Interactive : MonoBehaviour
{
/// <summary>
/// 这个是什么东西
/// </summary>
public enum ItemName{
,
};
public ItemName itemName;
//这是一对碰撞检测代码。当玩家进入将自身传给玩家。当玩家退出把玩家的catch清空
void OnTriggerEnter2D(Collider2D other){
if(other.TryGetComponent<MyPlayer>(out MyPlayer player))
player.catching = this;
}
void OnTriggerExit2D(Collider2D other)
{
if(other.TryGetComponent<MyPlayer>(out MyPlayer player)){
//如果目前退出当前交互区域的时候,玩家的捕捉物体是自己,才把玩家的捕捉清空。否则说明玩家在推出前就捕捉到了新的
//对象。这样是用来解决排布密集的可交互物体的问题
if(player.catching == this)player.catching = null;
}
}
public virtual void OnCall(){}
public virtual void OnBeGaveMoney(){}
}