Spell Casting

GameControl.cs

receives the player’s input, and sends it to spell library to learn if not learnt.

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

public class GameControl : MonoBehaviour {
	//savedata vars
	public static int chapterID;

	//temp vars
	public static bool casting;
	public static int[] circle;

	private int learning;
	private int imput;

	private SpellLibrary sl;

	void Awake () {
		chapterID = 0;
		circle = new int[] {7,7,7};
		casting = false;
		sl = GameObject.Find ("SpellLibrary").GetComponent<SpellLibrary>();
	}

	void OnMouseDown() {
		if (Element.eleCount == 3) {
			circle = new int[] { Element.firstEle, Element.secondEle, Element.thirdEle};
			Array.Sort (circle);
			imput = circle [0] * 100 + circle [1] * 10 + circle [2];
			Debug.Log (imput.ToString());

			GameObject.Find("Ele1").GetComponent<Symbol>().spriteID = 7;
			GameObject.Find("Ele2").GetComponent<Symbol>().spriteID = 7;
			GameObject.Find("Ele3").GetComponent<Symbol>().spriteID = 7;

			Element.EleCount (0);
			casting = true;

			//Spell Learning
			if (imput == 145) {
				learning = 0;
			} else if (imput == 245) {
				learning = 1;
			} else if (imput == 12) {
				learning = 2;
			} else if (imput == 25) {
				learning = 3;
			} else if (imput == 45) {
				learning = 4;
			} else if (imput == 456) {
				learning = 5;
			} else if (imput == 356) {
				learning = 6;
			} else if (imput == 235) {
				learning = 7;
			} else if (imput == 34) {
				learning = 8;
			}
			sl.Learn(learning);
		}
	}
}

Element.cs

attached to the elements symbols and receives the player’s click/tap.

adds a symbol on the crafted circle one by one.

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

public class Element : MonoBehaviour {
	public int elementID;

	public static int firstEle;
	public static int secondEle;
	public static int thirdEle;
	public static int eleCount;

	void Start () {
		firstEle = 7;
		secondEle = 7;
		thirdEle = 7;
		eleCount = 0;
	}

	void Update (){
	}

	public static void EleCount (int n) {
		eleCount = n;
	}

	void OnMouseDown(){
		if (eleCount == 0) {
			firstEle = this.elementID;
			GameObject.Find("Ele1").GetComponent<Symbol>().spriteID = firstEle;
			eleCount = eleCount + 1;
		} else if (eleCount == 1 && this.elementID != firstEle) {
			secondEle = this.elementID;
			GameObject.Find("Ele2").GetComponent<Symbol>().spriteID = secondEle;
			eleCount = eleCount + 1;
		} else if (eleCount == 2 && this.elementID != firstEle && this.elementID != secondEle) {
			thirdEle = this.elementID;
			GameObject.Find("Ele3").GetComponent<Symbol>().spriteID = thirdEle;
			eleCount = eleCount + 1;
		}
	}
}

Symbol.cs

attached to the empty circle, alters the sprite depending on the input.

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

public class Symbol : MonoBehaviour {

	public int id;
	public int spriteID;

	private int si;
	private string sn;

	private GameObject[] go;

	void Start () {
		spriteID = 7;
	}

	void Update () {
		if (this.spriteID &lt;= 6) {
			si = (this.id * 10) + this.spriteID;
			sn = si.ToString ();
			GameObject.Find (sn).GetComponent<SpriteRenderer>().enabled = true;
			this.spriteID = 8;
		} else if (this.spriteID == 7) {
			sn = "sym" + this.id.ToString ();
			go = GameObject.FindGameObjectsWithTag(sn);

			foreach (GameObject g in go) {
				g.GetComponent<SpriteRenderer>().enabled = false;
			}

			this.spriteID = 8;
		}
	}
}

Advertisements