38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
![]() |
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(){}
|
|||
|
}
|