对话实现
触碰npc产生对话
选中摄像机 ctrl+shift+f可以使得其对准当前scene的场景
using System.Collections; using System.Collections.Generic; using UnityEngine; using Fungus; public class NPCcontrol : MonoBehaviour {
public string ChatName;//这个名字是FlowChart中,块的名字,需要把这个变量设定为flowchart中块的名字 // Start is called before the first frame update private bool canChat = false; private void OnTriggerEnter(Collider other) {
canChat = true; } private void OnTriggerExit(Collider other) {
canChat = false; } private void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Say(); } } private void OnMouseDown() {
Say(); } void Say() {
if (canChat) {
//对话 Flowchart flowChart = GameObject.Find("Flowchart").GetComponent<Flowchart>(); if (flowChart.HasBlock(ChatName)) {
//执行对话 flowChart.ExecuteBlock(ChatName); } } } }
条件对话
带人物的对话

创建Character物体
设定名字:

选中对话即可设定人物

可以在这里设定立绘还有立绘的个数:


如果想要修改对话框,可以在这里自己修改

分支对话



然后即可触发不同对话
(但是这里会有个bug 当你处在最后一句话的时候,由于你处在npc可以对话的范围内,此时你按下空格键有两个作用,一个是结束最后一句对话,另外一个是同时还会重新触发对话
这是在有选择分支的情况下 当选择完之后进入了另外一个block 然后在这个block的最后一句话的时候如果按下空格键 此时会结束这个block的对话,而且还会触发原来的那个block的对话
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/232611.html原文链接:https://javaforall.net
