Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by karim_nasser · May 10, 2014 at 02:03 PM · c#guiinputboolean

GUIText which corresponds with a GUIBox

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);
                 }
             }
         }
     }
 
 }
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · May 10, 2014 at 02:13 PM 0
Share

Unity Answers addresses single, specific technical questions to help you write your code. I don't see a specific technical issue in your question, and I don't see any attempt at the code that matches your title.

avatar image karim_nasser · May 10, 2014 at 02:22 PM 0
Share

I wasn't sure how to begin. That code I posted is where players type the string in for the object. I don't know how to have that be called to a GUIBox and change color.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · May 10, 2014 at 03:35 PM

If your specific question is about changing color, as far as I know, you cannot change the color of a GUI.Box(). You can change the background texture, but if you were going to do that, you might as well use GUI.DrawTexture() instead, and use a red or a green texture. So that is the place to start. It would be best to have an array of boolean values that you could set to true when you wanted green. Example code. Put it on an empty game object in a new scene, initialize redTexure and greeTexture in the Inspector, and hit play:

 #pragma strict
 
 var redTexture : Texture2D;
 var greenTexture : Texture2D;
 var startRect = Rect(10,10,40,40);
 var padding = 3;
 
 private var state : boolean[] = new boolean[10];
 
 function Start() {
     state[3] = true;
     state[5] = true;
     state[8] = true;
 }
 
 function OnGUI() {
     var rect = startRect;
     
     for (var i = 0; i < state.Length; i++) {
         var tex = (state[i]) ? greenTexture : redTexture;
         GUI.DrawTexture(rect, tex);
         rect.x += rect.width + padding;
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Trying to Highlight text in order to copy and paste, but do not want the text to be editable. 1 Answer

Game Menus WIth Keyboard Input Control 1 Answer

(C#) A better way to limit actions to once per button press? 2 Answers

GetComponent, set boolean to true but it willn't revert 3 Answers

Touch Input with Event Trigger. How to handle with it properly. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges