Bomb Script

using UnityEngine;
using System.Collections;

public class GameScriptGrid : MonoBehaviour {

public GameObject[] totalList;
public Vector3[] initialStartPositions;
public GameObject correctText;
public GameObject incorrectText;
private Color clickColour = new Color(5,0,0);
public Color defaultColour;

private AudioSource audioSource;
public AudioClip correctClip;
public AudioClip incorrectClip;

private float correctClicks = 0;
private float incorrectClicks = 0;
private float level = 1;
private float timeBetweenNewAdded = 0; //In miliseconds
private float timeSinceLastChange = 0;

public TextMesh textMesh1;
public TextMesh textMesh2;
public TextMesh textMesh3;

// Use this for initialization
void Start ()
{
defaultColour = totalList [0].renderer.material.color;
audioSource = GetComponent ();
initialStartPositions = new Vector3[totalList.Length];
for (int i = 0; i < totalList.Length; i++) initialStartPositions [i] = totalList [i].transform.position; } // Update is called once per frame void Update () { ChangeMaxSimultaneousBasedOnLevel (); timeBetweenNewAdded = 2000 / level; if (timeSinceLastChange < (Time.realtimeSinceStartup * 1000)) { Debug.Log("Add New Cube Time!"); int cubeNo = GetRandomCube(); if (cubeNo > -1)
{
totalList[cubeNo].GetComponent().ColorToChangeTo = clickColour;
totalList[cubeNo].GetComponent().SetActive();
}
timeSinceLastChange = (Time.realtimeSinceStartup * 1000) + timeBetweenNewAdded;

}
DoInput ();

if (level > 4)
MoveThemRightLeft ();
if (level > 6)
Camera.main.GetComponent ().spin = true;
SimpleSway ();
}

public bool goRight = true;

void SimpleSway()
{
float x = this.transform.position.x;

if (goRight)x = x + (0.1f * Time.deltaTime);
else x = x – (0.1f * Time.deltaTime);
if (x > 0.2f)
goRight = false;
if (x < -0.2f) goRight = true; this.transform.position = new Vector3 (x, this.transform.position.y, this.transform.position.z); } int GetRandomCube() { int max = totalList.Length; int val = Random.Range (0, max); if (totalList [val].renderer.material.color == clickColour) return -1; else return val; } private float timeCounter = 0f; private float shiftTime = 2.0f; private float moveLeftRightSpeed = 0.5f; void MoveThemRightLeft() { timeCounter += Time.deltaTime; if (timeCounter > shiftTime)
{
Debug.Log(“CHANGE NOW…”);
timeCounter = 0f;
shiftTime = 4f;
moveLeftRightSpeed = -moveLeftRightSpeed;
}

for (int i = 0; i < totalList.Length; i++) { if (i < 3) totalList[i].transform.position = new Vector3(totalList[i].transform.position.x + moveLeftRightSpeed * Time.deltaTime, totalList[i].transform.position.y, totalList[i].transform.position.z); else if (i < 6) totalList[i].transform.position = new Vector3(totalList[i].transform.position.x - moveLeftRightSpeed * Time.deltaTime, totalList[i].transform.position.y, totalList[i].transform.position.z); else totalList[i].transform.position = new Vector3(totalList[i].transform.position.x + moveLeftRightSpeed * Time.deltaTime, totalList[i].transform.position.y, totalList[i].transform.position.z); } } void ChangeMaxSimultaneousBasedOnLevel() { float tmpLvl = (int)(correctClicks / 3f); //Debug.Log ("(int)(correctClicks / 2f): " + tmpLvl); if (tmpLvl > 100) {
tmpLvl = 11 + (tmpLvl / 50);
}
else
tmpLvl = 1 + (tmpLvl / 10);
//Debug.Log (“LEVEL: ” + tmpLvl);
level = tmpLvl;
textMesh1.text = “Level: ” + ((level * 10) – 9).ToString();
}

private void DoInput()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] rayCastHit;
rayCastHit = Physics.RaycastAll(ray);
if (rayCastHit.Length > 0)
{
CubeScript temp = rayCastHit[0].transform.gameObject.GetComponent();
Debug.Log(“SOMETHING HIT…”);
Debug.Log(rayCastHit[0].transform.gameObject.name);

if (temp.isActivated)
{
correctClicks++;
temp.SetDefault();
audioSource.clip = correctClip;
audioSource.Play();
Instantiate(correctText, temp.transform.position,Quaternion.identity);
}
else
{
//Incorrect Hit
Instantiate(incorrectText, temp.transform.position, Quaternion.identity);
audioSource.clip = incorrectClip;
audioSource.Play();
incorrectClicks++;
textMesh2.text = “Misses: ” + incorrectClicks.ToString() + ” / 5″;
}
}
}

}
}