I want to create a game where all tiles must be rotated to the correct position. I have 15 tiles with a script attached which rotates them 90 degrees on each click. I can detect when each tile is in the correct position but what I am having trouble doing is detecting when ALL 15 are in the correct position.
Here is a screen shot of my stage
https://www.dropbox.com/s/9ag4ly2bil1mzf1/Untitled-1.jpg?dl=0
I was thinking I can create an empty game object and attach a new script with code to get the value from each tile and check if all are true (in the correct position).
Here is my basic code for the rotation script
using UnityEngine;
using System.Collections;
public class rotate : MonoBehaviour {
public float rotationAnswer;
// Use this for initialization
void Start() {}
// Update is called once per frame
void Update() {}
float rotationValue = 0;
void OnMouseDown(){
transform.Rotate(Vector3.up * 90);
rotationValue = transform.rotation.eulerAngles.y;
Debug.Log ( rotationValue );
if ( rotationValue == rotationAnswer)
{
Debug.Log ( "Correct" );
switch (this.name )
{
case "tile1":
}
Debug.Log ( GameObject.Find("GameComplete").GetComponent<TileGameComplete>().totalCorrectTiles ))
} else {
Debug.Log ( "Wrong" );
}
}
}
Here is my basic code for the detection and complete game script
using UnityEngine;
using System.Collections;
public class TileGameComplete : MonoBehaviour {
public int currentCorrectTiles = 0;
public bool tile1 = false;
public bool tile2 = false;
public int totalCorrectTiles = 15;
// Use this for initialization
void Update()
{
GameObject.Find("Tile1").GetComponent<rotate>().done
if (tile1 && tile2)
{
Debug.Log ("You've won");
}
}
}
How would you go about solving this problem in C#. Thanks :)