I’m making a game where a player clicks an object eg. bed and has to type what it is into a GUITextField. There are ten words per scene and I want to create a GUIBox in each which charts the entering of each word and when entered correctly/incorrectly the adjoining word changes to green/red. My code thus far is below. Thanks in advance.
using UnityEngine;
using System.Collections;
public class Bed : MonoBehaviour {
public bool clickedBed = false;
public string bed = "Type Here";
void OnGUI() {
if (clickedBed) {
bed = GUI.TextField (new Rect (200, 78, 200, 20), bed, 25);
}
}
void OnMouseUpAsButton() {
Debug.Log ("Mouse DOWN!!!");
clickedBed = true;
}
void Update() {
if (Input.GetKeyUp (KeyCode.Return)) {
clickedBed = false;
// TODO proces guess
}
if (Input.GetMouseButton (0)) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo = new RaycastHit();
if (Physics.Raycast(ray, out hitInfo, 100.0f)) {
if (hitInfo.collider.gameObject.Equals(gameObject)) {
Debug.Log ("Mouse Clicked!!!");
clickedBed = true;
} else {
GameObject go = hitInfo.collider.gameObject;
while (go.transform.parent != null) {
go = go.transform.parent.gameObject;
if (go.Equals(gameObject)) {
Debug.Log ("Mouse Clicked!!!");
clickedBed = true;
}
}
//Debug.Log ("Hit: " + hitInfo.collider.gameObject);
//Debug.Log ("Should Hit: " + gameObject);
}
}
}
}
}