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 RayneAvalon · Apr 22, 2013 at 06:08 AM · c#guitriggertexttimer

Help with making a triggered gui message

alright so this is like the fourth time i have asked for help on this same project and i apologize to everyone for being so bad at coding. it has never been my strong point, the thought process for coding just is not how my brain is wired. all im trying to do here is simply make it so that when a player gets the password wrong in my keypad script a message pops up on the screen for like 3 or so second telling them they got it wrong and then disappears, but so far i cant even get my message to display. i would greatly appreciate any help as always. my code is listed below.

 using UnityEngine;
 using System.Collections.Generic;
 using System.Collections;
 using System.Linq;
 
 
 
 public class KeyPad: MonoBehaviour {
     //public variables
     public Texture2D icon;
     public string SetPassword = "12345";
     public string PlayerPassword = "";
     public string message = "Incorrect Password please try again";
     public bool KeyPadEnabled = false;
     public bool DoorIsOpen = false;
     public Transform target; 
     
     public MouseLook Pc;
     public MouseLook Mc;
      
 
     
     //trigger used to enable gui elements when player enters trigger zone
     void OnTriggerEnter (Collider other) {
         
         if(other.gameObject.tag.Equals ("Player"))
         {
             Pc.enabled=false;
             Mc.enabled=false;
             KeyPadEnabled = true;
         }
     
     }
     
     //trigger used to disable gui elements when player enters trigger zone
     void OnTriggerExit (Collider other) {
         
         if(other.gameObject.tag.Equals("Player"))
         {
             Pc.enabled=true;
             Mc.enabled=true;
             
             KeyPadEnabled = false;
             PlayerPassword = "";
         
             if( DoorIsOpen == true)
             {
                 target.Translate (Vector3.back *250* Time.deltaTime);
                 DoorIsOpen = false;
             }
         }
         
     }
         
     //gui function
     void OnGUI () {
         
         //check if gui elemnts should be shown.
         if(KeyPadEnabled == true)
         {
             //display gui elemnts
             GUI.Box (new Rect (10,10,300,300), new GUIContent(icon));
             PlayerPassword = GUI.PasswordField (new Rect(60, 60, 200, 35), PlayerPassword, "*"[0],45);
             
             //check for player input
             if(Input.GetKeyUp(KeyCode.KeypadEnter))
             {  
                 //check passwords
                 if(PlayerPassword.Equals (SetPassword))
                 {
                 //translate targer and set control variable to true
                 target.Translate (Vector3.forward *150* Time.deltaTime);
                 DoorIsOpen = true;
                 }
                 else
                 {
                     GUI.Label( new Rect(100, 150, 100, 35), message);
                     PlayerPassword = "";
                 }
                 
             }
         
         }
     }
             
     
 
 }


 
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SubatomicHero · May 03, 2013 at 10:22 AM

Not sure if this is still open or not, but instead of using

 if(PlayerPassword.Equals (SetPassword))

try using

 PlayerPassword == SetPassword

The equals function compares a string to an object, rather than string to string. Also what you need to do to display the message for three seconds is start a timer in the else statement

 // declared as a class member
 float displayMessage = 3.0f
 
 // else statement updated
 else
 {
      displayMessage -= Time.deltaTime;
      if (displayMessage > 0)
      {
           GUI.label(new Rect(100, 150, 100, 35), message);
           PlayerPassword = "";
           displayMessage = 3.0f;
      }
 }
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

12 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

Related Questions

How can I make a quest system? 2 Answers

Text object can't be edited 3 Answers

C# countdown timer 9 Answers

Timescale not affect timer? (C#) 2 Answers

C# GUI Button 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