Skip to content
Permalink
64995e7aa2
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
120 lines (97 sloc) 2.68 KB
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Raycast : MonoBehaviour {
public GameObject cube1;
public GameObject cubeGreen;
public GameObject cubeYellow;
public GameObject cubePurple;
public GameObject xText;
public GameObject greenText;
public GameObject yellowText;
public GameObject purpleText;
public GameObject cylR;
public GameObject cylG;
public GameObject cylY;
public GameObject cylP;
public GameObject boxR;
public GameObject boxG;
public GameObject boxY;
public GameObject boxP;
public bool haveRed = false;
public bool haveGreen = false;
public bool haveYellow = false;
public bool havePurple = false;
public int BoxIndex = 0;
public int WinIndex = 0;
public Text win;
// Use this for initialization
void Start () {
boxR.active = false;
boxG.active = false;
boxY.active = false;
boxP.active = false;
win.enabled = false;
}
// Update is called once per frame
void Update () {
if (WinIndex == 4) {
win.enabled = true;
}
if (Input.GetMouseButtonDown (0)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
if (hit.collider.gameObject == cube1) {
xText.GetComponent<Text> ().color = Color.red;
cube1.active = false;
haveRed = true;
}
else if (hit.collider.gameObject == cubeGreen) {
greenText.GetComponent<Text> ().color = Color.green;
cubeGreen.active = false;
BoxIndex++;
haveGreen = true;
}
else if (hit.collider.gameObject == cubeYellow) {
yellowText.GetComponent<Text> ().color = Color.yellow;
cubeYellow.active = false;
haveYellow = true;
}
else if (hit.collider.gameObject == cubePurple) {
purpleText.GetComponent<Text> ().color = Color.magenta;
cubePurple.active = false;
havePurple = true;
}
else if (hit.collider.gameObject == cylP) {
if (havePurple == true) {
purpleText.GetComponent<Text> ().color = new Color(227f,227f,227f);
boxP.active = true;
WinIndex++;
}
}
else if (hit.collider.gameObject == cylR) {
if (haveRed == true) {
xText.GetComponent<Text> ().color = new Color (227f, 227f, 227f);
boxR.active = true;
WinIndex++;
}
}
else if (hit.collider.gameObject == cylY) {
if (haveYellow == true) {
yellowText.GetComponent<Text> ().color = new Color (227f, 227f, 227f);
boxY.active = true;
WinIndex++;
}
}
else if (hit.collider.gameObject == cylG) {
if (haveGreen == true) {
greenText.GetComponent<Text> ().color = new Color (227f, 227f, 227f);
boxG.active = true;
WinIndex++;
}
}
}
}
}
}