Skip to content

Instantly share code, notes, and snippets.

@bibinba
Last active October 19, 2019 11:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bibinba/8821d127684c4b87c8cd05550731c4bf to your computer and use it in GitHub Desktop.
Save bibinba/8821d127684c4b87c8cd05550731c4bf to your computer and use it in GitHub Desktop.
【unity1week】Fungusを使って会話!【お題:さがす】に使ったスクリプト
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Fungus;
public class getkey : MonoBehaviour
{
public Camera camera_object; //カメラを取得
private RaycastHit hit; //レイキャストが当たったものを取得する入れ物
private bool isTalking = false;
private int sweets = 0;
public Flowchart flowChart;
public AudioSource find;
private void Start()
{
StartCoroutine(Talk("start"));
}
void Update()
{
if (Input.GetMouseButtonDown(0)) //マウスがクリックされたら
{
Ray ray = camera_object.ScreenPointToRay(Input.mousePosition); //マウスのポジションを取得してRayに代入
if (Physics.Raycast(ray, out hit)) //マウスのポジションからRayを投げて何かに当たったらhitに入れる
{
if (hit.collider.gameObject.tag == "key")
{
Destroy(hit.collider.gameObject);
find.Play();
sweets++;
if (sweets < 3)
{
OnGetKey();
}
else
{
OnEnd();
}
Debug.Log("sweets:" + sweets);
}
}
}
}
private void OnGetKey()
{
Debug.Log("お菓子をクリック");
StartCoroutine(Talk("getkey"));
}
private void OnEnd()
{
StartCoroutine(Talk("end"));
Debug.Log("3つそろった");
}
IEnumerator Talk(string message)
{
if (isTalking)
{
yield break;
}
isTalking = true;
GetComponent<FirstPersonAIO>().enabled = false;
flowChart.SendFungusMessage(message);
yield return new WaitUntil(() => flowChart.GetExecutingBlocks().Count == 0);
isTalking = false;
GetComponent<FirstPersonAIO>().enabled = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment