CangJie/Assets/Scripts//Interactable.cs
Roman b96029fd5e 任务:编写序章场景逻辑
1.编写交互操作逻辑,我会用脚本给玩家物体添加一个子物体,子物体有一个触发器,当玩家按下交互键,通过回调看是否有Catch到的可交互物体,若有,我会触发可交互物体的OnCall,若没有,则不做反应。

2.编写可交互物体基类,可交互物体继承自Event,Start时检查碰撞盒状态。当检查到玩家进入触发器,把自己交给玩家的Catch。当检查到玩家离开触发器,看目前的Catch是否和自己一样,若一样则清除Catch,若不一样说明已经Catch了其他东西,不做反应。

3.编写绳结类,继承自可交互物体。当交互,给中介者发送信息,让中介者更改记录的当前记录的绳结是哪一个
(1.内含一个来自中介者的枚举类型的变量,记录自己属于哪一种绳结
(2.当OnCall,把自己的类型发给中介者

4.编写绳结中介者,负责玩家、皇帝和绳结的信息交流。
(1.有一个枚举类型,内含三种绳结种类
(2.有一个枚举类型的变量,记录当前记录的是哪一个绳结
(3.当绳结发来信息,更新记录的当前绳结

5.添加新的按键监听,并增加PlayerControl的虚函数

6.编写黄帝类
(1.继承自可交互物体
(2.内含一个来自中介者的枚举类型,记录皇帝对哪一种绳结提出要求
(3.当OnCall,检查中介者中记录的绳结和要求的是不是同一种,若是则触发后续流程,若不是,则触发摇头等动作,目前不做反应
(4.内含函数与后期外界对接,用来指定皇帝需要的绳结类型

*记得给Player类的Interact函数加上Base

我是每天上班提醒小助手,今天你上班了吗?😺
2022-03-13 21:40:55 +08:00

39 lines
947 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 可交互物件基类
/// </summary>
public class Interactable : Event
{
void Start()
{
//检查触发器
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);
}
}
void OnTriggerExit2D(Collider2D other)
{
if (other.TryGetComponent<PlayerInteract>(out PlayerInteract playerInteract))
{
playerInteract.CancleCatched(this);
}
}
}