一个任务的fungus
声明fungus 设置一个开关,当触发碰撞器时,将开关打开,当在持续碰撞时如是碰到的是人物,并且按下空格且开关为开,就执行对话重载名字并且关闭开关//多个任务的时候就是加个else 其他都一样
using System;
using System.Collections;
using System.Collections.Generic;
using Fungus;
using UnityEngine;
public class FungunNpcGrandFather : MonoBehaviour
{
private AllTask _allTask;
private Flowchart flowChart;
private bool _canSay;
private void Start()
{
_allTask = GameObject.Find("CanvasScene").transform.GetChild(0).GetChild(7).GetComponent<AllTask>();
flowChart = GameObject.Find("Flowchart").GetComponent<Flowchart>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
_canSay = true;
}
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (_allTask.enemyNum>=50&&_canSay)
{
//执行对话
flowChart.ExecuteBlock("Task4");
_canSay = false;
}
else if (_canSay)
{
//执行对话
flowChart.ExecuteBlock("Task3");
_canSay = false;
}
}
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices.ComTypes;
using Fungus;
using UnityEngine;
using UnityEngine.EventSystems;
using Collision = UnityEngine.Collision;
public class FungusNpc : MonoBehaviour
{
public string chatName;
private bool _canSay;
private Flowchart _flowChart;
private void Start()
{
_flowChart = GameObject.Find("Flowchart").GetComponent<Flowchart>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
_canSay = true;
}
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
if (Input.GetKeyDown(KeyCode.Space))
{
if (_canSay)
{
//执行对话
_flowChart.ExecuteBlock(chatName);
_canSay = false;
}
}
}
}
}