Skip to content

Instantly share code, notes, and snippets.

@bibinba bibinba/getkey.cs
Last active Oct 19, 2019

Embed
What would you like to do?
【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
You can’t perform that action at this time.