首页 > 解决方案 > 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");
    }
}

标签: unity3d

解决方案


OnTriggerEnter被调用一次,并且您只在一帧期间收听输入。考虑将此部分移至更新:

if (enter && Input.GetKeyDown(KeyCode.E))
{
    Fungus.Flowchart.BroadcastFungusMessage("StartConversation");
}

或更改OnTriggerEnterOnTriggerStay


推荐阅读