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 Alanimator · Apr 08, 2012 at 02:53 AM · guiarraystextfieldoncontrollercolliderhit

text fields and GUI

/*Heyy

I have a program here which many of you will find useful but there is one problem .

okay , in this script there is a tag i created called "xclpanel" , whenever a character steps on the object tagged with xclpanel a GUI window will appear which will generate a question to the player . I have created a text field but i have not fixed it to react to the user pressing the enter button after inputting an answer . I the main problem is that whenever the xclock is true ( the character has stepped on the panel) the Text field does not appear when xclock is set to false at the END of the function to generate the windows .

could you please help me to get the text field to appear with the question when the panel is stepped on and disappear when the character moves off the panel

and how would i go about creating an answer for the question generated so that when the user presses the enter button the answer is checked :s

Here is my Java script *

*/

var doWindow : boolean = true;

private var xclock = false;

var stringToEdit : String = "";

function OnControllerColliderHit (hit: ControllerColliderHit)

{

if(hit.gameObject.tag == "xclpanel")

{

xclock= true; // character stepped on xclock

}

}

function DoWindow (windowID : int) {

}

function OnGUI ()

{

    if (xclock)



  {



 



 



// GUI DISPLAYED IF PANEL IS HIT

   GUI.color = Color.yellow;



    GUI.backgroundColor = Color.yellow;



   GUI. Window (0, Rect (1,40,300,140), DoWindow, " what is english Language and why is it important  ");



   

   // THIS IS THE TEXT FIELD



   stringToEdit = GUI.TextField (Rect (1, 180, 300, 50), stringToEdit, 200);  

  



   



xclock = false ; // the TEXT FIELD WILL NOT APPEAR IF THIS IS NOT OMITTED ( THIS IS THE PROBLEM)

}

}

Comment
Add comment · Show 1
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 Kleptomaniac · Apr 08, 2012 at 04:46 AM 1
Share

Could you please format your code properly? Highlight the whole code and press the 101010 button in the toolbar.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by GuyTidhar · Apr 08, 2012 at 07:47 AM

First thing: Remove the:

 xclock = false;

From the OnGUI() function. What you basically did is once you display the clock - you hide it.

2nd, add the following function to the same script:

 function OnCollisionExit(collisionInfo : Collision)
 {
     if ( collisionInfo.collider.tag == "xclpanel" )
     {
          xclock = false;
     }
 }

By this code, you are telling the controller, to hide the clock once you 'exit' the collider tagged 'xclpanel'.

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

6 People are following this question.

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

Related Questions

Backspace in limited length textfield causes ArgumentOutOfRangeException 1 Answer

How to select a texture in an inventory? 0 Answers

GUILayout Textfield not editable just static 1 Answer

Assets/Scripts/Inventory.cs(9,40): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `Inventory.differentItems' 1 Answer

How to slow down GUI 2 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