Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by xavier12321 · Nov 24, 2015 at 07:10 PM · uitext

Why does my text doesn't stay on screen?

Hi! As you might imagine, I'm kinda new to this scripting, programming thing. I'm trying to create a text game ( You know, those old school games with only text on the screen?). I'm trying to make an if statement about a key or something. I want my text to change if the bool ''haskey'' is false.

I can see the text wants to change but it changes back to the original text. My script looks like that.

void State_OutsideCell1 () { hasKey1 = false; text.text = "you see a door and a key, press T to take the key or press D to open the door.";

     // You have the key and you open the door
     if (hasKey1 =    = true && Input.GetKeyDown (KeyCode.D)) {
         text.text = "You enter the door blablabla";
         myStates = States.whatever;
     }

     // You don't have the key
     if (Input.GetKeyDown (KeyCode.D) && hasKey1 == false) 
         text.text = "You don't have a key press blabla to blabla.";


 }

I'm pretty sure it has something to do with the first line but I don't know how to change it so it's not THE line of the method.

Thanks for your help!

Comment
Add comment · Show 3
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 xavier12321 · Nov 24, 2015 at 07:21 AM 0
Share

Oh, and it is in C#. Sorry ! :x

avatar image Le-Pampelmuse xavier12321 · Nov 24, 2015 at 07:26 PM 0
Share

Hi, welcome to Unity Answers. Please have a look at the FAQ and the User Guide, so you can use this forum efficiently in the future. :)

Please make sure you edit your question using the little black wheel on the right and format it properly using the 101 010 button for code parts, so it is easy to read for others.

 if (has$$anonymous$$ey1 =    = true && Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.D))

..will not compile because of all the spaces between the "=="

I recommend you watch the basic scripting tutorials 1-3 and 5-9 here.

This should give you a stable knowledge on common Unity scripting tasks. ;)

Please watch them carefully and hopefully you can tell by yourself why your script is not working. If you have any trouble following them, feel free to ask, since you seem to be a beginner and willing to learn something ;)

Have a nice day.

avatar image tanoshimi · Nov 24, 2015 at 07:28 PM 0
Share

Please format your code using the 101010 button - it's hard to see what the first line is you're talking about, but it looks to be has$$anonymous$$ey1 = false;. So, you're setting has$$anonymous$$ey1 to be false every time this function is called, and there doesn't seem to be anywhere where you set it to true?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xavier12321 · Nov 25, 2015 at 03:23 PM

     void State_OutsideCell1 () {
 
             if (hasKey1 == false)
             text.text = "You are in front of a door and there is a key to your left. \n\n Press o to open the door \nPress T to take the key.";
         {
             if (hasKey1 == true)
             text.text = "You have a key in hand. press o to open the door";
         
             else if (hasKey1 == true & Input.GetKeyDown (KeyCode.O)) 
             myStates = States.door1;
 
             else if(hasKey1 == false & Input.GetKeyDown(KeyCode.T))
                 text.text = "You don't have a key! Press T to take the key.";
             hasKey1 = true;
             
         }
     }

I'm trying something like that. It just wont work. when I enter this ''Room'', it makes haskey1 true and the text is ''You are in front of a door and there is a key to your left (...) ''.

I'm pretty sure it has everything to do with the way I typed my if statements and the curly bracers.

Note: I made a way over complicated system to make this work but I don't want to use that. See for yourself.

     /* void State_OutsideCell1 () {
         text.text = "As you get closer to the door, it gets bigger. You think it is a bit intimidating. Your head starts to hurt like crazy. " +
             "What is behind that door? To your left, there is a key on the wall.\n\n press T to take the key.\n\n press D to open the door. ";
         if (hasKey1 == true && Input.GetKeyDown (KeyCode.D)) // 
             myStates = States.door1;
          else if (Input.GetKeyDown (KeyCode.D) && hasKey1 == false) //
             myStates = States.HasNoKey1;
         else if (Input.GetKeyDown (KeyCode.T) && hasKey1 == false) //
             myStates = States.Key1;
         else if (Input.GetKeyDown (KeyCode.T) && hasKey1 == true) //
             myStates = States.HasKey1; 
     }
     void State_HasKey1 () {
         text.text = "you already took the key and There is nothing left on the wall. Press B to go back";
         if (Input.GetKeyDown (KeyCode.B))
             myStates = States.OutsideCell1;
     }
 
     void State_HasNoKey1 () {
         text.text = "You feel nauseous as you reach for the door knob. Why is that? The door is locked and you can't open it without a key." +
             "Press B to go back";
             if(Input.GetKeyDown(KeyCode.B))
                 myStates = States.OutsideCell1;
     }
     void State_Key1 () {
         text.text = "Has you reach for the key, your head suddenly feels like it is going to explode. You take a deep breath and clear your mind." +
             "\n\n press t to take the key"; 
         hasKey1 = true;
         if (Input.GetKeyDown (KeyCode.T))
         myStates = States.OutsideCell1;
 
 
     }
 
     void State_Door1 () {
         text.text = "You use the key on the lock and open the door. you shit on your chest. press anykey to masturbate.";
     } */

it's just too long and stupid... But it works.... ^,^

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

null reference exception with text 0 Answers

Show a text in the position of a GameObject 0 Answers

Can not properly display the score on pong game 0 Answers

I have a score displayed constantly in my game, but I can't get it to work for my game-complete screen? Help? 0 Answers

UI Text rendering in front and behind planes 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