Puzzle Scenes

Puzzle.cs

receives the player’s input and judge correct or not

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Puzzle : MonoBehaviour {
	public int key01;
	public int key02;
	public int key03;
	public string whatToDo;
	public string helper;
	public string correct;
	public string incorrect;

	public AudioClip success;

	public string nextScene;

	private Book book;
	private GameObject pui;
	private Text pt;
	private SceneTrans st;
	private SoundEffect se;

	private int phase;

	private int a;
	private int b;
	private int c;
	private int amberInput;

	void Start () {
		phase = 0;
		book = GameObject.Find ("Book").GetComponent<Book>();
		pui = GameObject.Find ("PuzzleUI");
		pt = GameObject.Find ("PT").GetComponent<Text>();
		st = GameObject.Find ("trans").GetComponent<SceneTrans> ();
		se = GameObject.Find ("SE").GetComponent<SoundEffect> ();
	}

	void Text (string txt) {
		book.Close();
		pui.SetActive (true);
		pt.text = txt;
	}

	void Update () {
		if (phase == 0) {
			Text (whatToDo);
			phase = 1;
		} else if (phase == 2 && GameControl.casting == true){
			
			a = GameControl.circle [0];
			b = GameControl.circle [1];
			c = GameControl.circle [2];
			Debug.Log (a.ToString() + b.ToString() + c.ToString());

			amberInput = a * 100 + b * 10 + c;

			GameControl.circle = new int[] { 7, 7, 7 };
			GameControl.casting = false;

			if (amberInput == key01 || amberInput == key02 || amberInput == key03) {
				se.Sound (success);
				Text ("<b>" + helper + ":</b>\n" + correct);
				phase = 3;
			} else {
				Text ("<b>" + helper + ":</b>\n" + incorrect);
				phase = 4;
			}

		}
	}

	void OnMouseDown (){
		if (phase == 1) {
			book.Open(0);
			pui.SetActive (false);
			phase = 2;
		} else if (phase == 3) {
			Destroy (this.GetComponent<BoxCollider2D>() );
			st.Fade (nextScene);
		} else if (phase == 4) {
			phase = 0;
		}
	}
}

Advertisements