unity3d - Unity Fungus Flowchart 没有收到我的脚本的消息
问题描述
我希望我的播放器与对象交互,所以我使用 Fungus 和一个脚本,当播放器足够靠近对象并按 E 时,它会向流程图发送一条消息以激活一个块。但它不起作用。
剧本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EventTrigger : MonoBehaviour
{
public bool enter;
int count = 1;
// Use this for initialization
void Start()
{
enter = false;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player" || other.gameObject.tag == "NPC")
{
enter = true;
if (enter && Input.GetKeyDown(KeyCode.E))
{
Fungus.Flowchart.BroadcastFungusMessage("StartConversation");
}
}
Debug.Log("Entered");
}
void OnTriggerExit(Collider other)
{
if (other.gameObject.tag == "Player" || other.gameObject.tag == "NPC")
{
enter = false;
count = 1;
}
Debug.Log("Exited");
}
}
解决方案
OnTriggerEnter
被调用一次,并且您只在一帧期间收听输入。考虑将此部分移至更新:
if (enter && Input.GetKeyDown(KeyCode.E))
{
Fungus.Flowchart.BroadcastFungusMessage("StartConversation");
}
或更改OnTriggerEnter
为OnTriggerStay
推荐阅读
- azure-logic-apps - Azure 逻辑应用程序 - 如何为案例添加具有多个值的开关案例
- python - 用于句子嵌入的 KMeans
- python - discord.py bot 看不到成员
- reactjs - 为什么我的组件基于 redux 的 props 没有更新?
- regex - 正则表达式:匹配和提取浮点数
- reactjs - 工具提示未显示
- python - Django 在模板中使用两个不同的数据集填充表
- css - 这个布局可以用 Flexbox 完成吗
- reactjs - React 不会在状态更改时重新渲染
- java - Apache POI:迭代 docx.getBodyElements() 时如何获取页码