columns wont pause on mouseclick
Im making a game where there are three columns moving either up or down. I want one of the columns pause for a second when I click on it, however it is not working. Here is my code:
and help would be amazing!
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Main : MonoBehaviour {
public static float Range;
public GameObject[] squaresDownArray;
public GameObject[] squaresUpArray;
public GameObject square;
int index;
public Color[] colourArray;
public Vector2 leftSpawnPosition;
public Vector2 midSpawnPosition;
public Vector2 rightSpawnPosition;
public float spawnTimer;
private float spawnCounter;
private int squareIndexCounter;
public bool leftColumnOn;
public bool midColumnOn;
public bool rightColumnOn;
// Use this for initialization
void Start ()
{
InvokeRepeating ("TimerTick", 0, 1);
}
// Update is called once per frame
void Update ()
{
spawnCounter += Time.deltaTime;
}
public void TimerTick ()
{
/*
if (spawnCounter >= spawnTimer) {
GameObject lSquare = Instantiate (square, leftSpawnPosition, Quaternion.identity);
lSquare.tag = "SquareLeft";
//lSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
lSquare.GetComponent<MeshRenderer> ().materials [0].color = colourArray [Random.Range (0, colourArray.Length)];
squareIndexCounter++;
if (squareIndexCounter >= colourArray.Length) {
squareIndexCounter = 0;
}
GameObject mSquare = Instantiate (square, midSpawnPosition, Quaternion.identity);
mSquare.tag = "SquareMid";
//mSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
mSquare.GetComponent<MeshRenderer> ().materials [0].color = colourArray [Random.Range (0, colourArray.Length)];
squareIndexCounter++;
if (squareIndexCounter >= colourArray.Length) {
squareIndexCounter = 0;
}
GameObject rSquare = Instantiate (square, rightSpawnPosition, Quaternion.identity);
rSquare.tag = "SquareRight";
//rSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
rSquare.GetComponent<MeshRenderer> ().materials [0].color = colourArray [Random.Range (0, colourArray.Length)];
squareIndexCounter++;
if (squareIndexCounter >= colourArray.Length) {
squareIndexCounter = 0;
}
}
*/
if (leftColumnOn) {
if (spawnCounter >= spawnTimer) {
GameObject lSquare = Instantiate (square, leftSpawnPosition, Quaternion.identity);
lSquare.tag = "SquareLeft";
//lSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
lSquare.GetComponent<MeshRenderer> ().materials [0].color = colourArray [Random.Range (0, colourArray.Length)];
squareIndexCounter++;
if (squareIndexCounter >= colourArray.Length) {
squareIndexCounter = 0;
}
foreach (GameObject square in GameObject.FindGameObjectsWithTag("SquareLeft")) {
square.GetComponent<SquareScript> ().Move ("down");
}
}
}
if (midColumnOn) {
if (spawnCounter >= spawnTimer) {
GameObject mSquare = Instantiate (square, midSpawnPosition, Quaternion.identity);
mSquare.tag = "SquareMid";
//mSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
mSquare.GetComponent<MeshRenderer> ().materials [0].color = colourArray [Random.Range (0, colourArray.Length)];
squareIndexCounter++;
if (squareIndexCounter >= colourArray.Length) {
squareIndexCounter = 0;
}
foreach (GameObject square in GameObject.FindGameObjectsWithTag("SquareMid")) {
square.GetComponent<SquareScript> ().Move ("up");
}
}
}
if (rightColumnOn) {
if (spawnCounter >= spawnTimer) {
GameObject rSquare = Instantiate (square, rightSpawnPosition, Quaternion.identity);
rSquare.tag = "SquareRight";
//rSquare.GetComponent<SpriteRenderer> ().color = colourArray [squareIndexCounter];
rSquare.GetComponent<MeshRenderer> ().materials [0].color = colourArray [Random.Range (0, colourArray.Length)];
squareIndexCounter++;
if (squareIndexCounter >= colourArray.Length) {
squareIndexCounter = 0;
}
foreach (GameObject square in GameObject.FindGameObjectsWithTag("SquareRight")) {
square.GetComponent<SquareScript> ().Move ("down");
}
}
}
leftColumnOn = true;
midColumnOn = true;
rightColumnOn = true;
}
}
Comment