Book

Book.cs

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

public class Book : MonoBehaviour {

	private GameObject[] page;
	private BoxCollider2D bc;
	private GameObject anim;

	void Awake () {
		anim = GameObject.Find ("SpellCasting/Anim");
		page = new GameObject[] { GameObject.Find ("SpellCasting"),  GameObject.Find ("SpellLibrary")};
		bc = GameObject.FindWithTag ("GameController").GetComponent<BoxCollider2D> ();
	}

	public void Open(int id){
		bc.enabled = false;
		anim.SetActive (false);
		page [id].SetActive (true);
		//Debug.Log ("page opened.");
	}

	public void PageTurn(int pg){
		foreach (GameObject p in page) {
			p.SetActive (false);
		}
		anim.SetActive (true);
		page [pg].SetActive (true);
		//Debug.Log ("page turned.");
	}

	public void Close(){
		bc.enabled = true;
		foreach (GameObject p in page) {
			p.SetActive (false);
		}
	}

}

Page.cs

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

public class Page : MonoBehaviour {
	public enum TargetPage
	{
		CASTING,
		LIBRARY
	}

	public TargetPage targetPage;

	private int page;
	private Book bk;

	void Awake () {
		bk = GameObject.Find ("Book").GetComponent<Book>();
		if (targetPage == TargetPage.CASTING) {
			page = 0;
		} else if (targetPage == TargetPage.LIBRARY) {
			page = 1;
		}
	}

	void OnMouseDown(){
		bk.PageTurn (page);
	}
}

Advertisements