Last active
October 19, 2019 11:51
-
-
Save bibinba/8821d127684c4b87c8cd05550731c4bf to your computer and use it in GitHub Desktop.
【unity1week】Fungusを使って会話!【お題:さがす】に使ったスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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