2021-12-11 02:12:12 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 可交互物体基类
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Interactive : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 这个是什么东西
|
|
|
|
|
/// </summary>
|
|
|
|
|
public enum ItemName{
|
|
|
|
|
塞钱箱,
|
2021-12-17 01:27:10 +08:00
|
|
|
|
硬币,
|
|
|
|
|
男童
|
2021-12-11 02:12:12 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
2021-12-17 01:27:10 +08:00
|
|
|
|
//触发一个离开事件
|
|
|
|
|
OnLeave();
|
2021-12-11 02:12:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-17 01:27:10 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 交互键按下触发
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void OnCall(){}
|
|
|
|
|
public virtual void OnBeGaveMoney(){}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 交互键抬起触发
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void OnCallCancel(){}
|
|
|
|
|
public virtual void OnLeave(){}
|
|
|
|
|
public virtual int RetuenState(){return 0;}
|
2021-12-11 02:12:12 +08:00
|
|
|
|
}
|