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 /
This question was closed Dec 04, 2019 at 03:49 AM by hballamco for the following reason:

Question is off-topic or not relevant

avatar image
0
Question by hballamco · Nov 15, 2019 at 01:29 PM · setactiveif statementupdate function

How to hide a text and show another when Space bar is clicked?,How to hide text after pressing space?

  void Update()
     {
         if (active==true)
         {
             Motion();
             Rotate();
         }
         else
         {
 
         }
 
         // Below is set of lines to be displayed once player face them
         var fwd = transform.TransformDirection(Vector3.forward);
         if (Physics.Raycast(transform.position, fwd, out hit, Reach) && hit.transform.tag == "Bed")
         {
             interaction.SetActive(true);
             if (Input.GetKey(KeyCode.Space))
             {
                 bedLine.SetActive(true);
             }
         }
         else if (Physics.Raycast(transform.position, fwd, out hit, Reach) && hit.transform.tag == "Toilet")
         {
             interaction.SetActive(true);
             if (Input.GetKey(KeyCode.Space))
             {
                 toiletLine.SetActive(true);
             }
         }
         else if (Physics.Raycast(transform.position, fwd, out hit, Reach) && hit.transform.tag == "Speaker")
         {
             interaction.SetActive(true);
 
             if (Input.GetKey(KeyCode.Space))
             {
                 speakerLine.SetActive(true);
                 interaction.SetActive(false);
             }
 
         }

So, in the second "else if", I would like for the interaction line to hide and speaker line to show. I tried to include another if statement but it didn't change anything. Thus, in my game, whenever I go near the object with speaker tag, interaction appears as it should but when i press space bar the interaction line hide and shows resulting in showing both lines.

by the way I'm 2 weeks old with Unity :)

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

  • Sort: 
avatar image
0

Answer by mxoconnell · Nov 15, 2019 at 03:07 PM

Move this line

Input.GetKey(KeyCode.Space)

To the top of your code and capture it in a boolean value that you can reference later. Or better yet, have a function called CollectInput that checks that stuff for you. See if it is correctly firing by printing its value.

Comment
Add comment · Show 2 · 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
avatar image hballamco · Nov 15, 2019 at 03:33 PM 0
Share

Forgive my lack of Unity knowledge. Would you $$anonymous$$d copying my script with the changes you pointed at? Thanks a lot.

avatar image mxoconnell · Nov 15, 2019 at 07:58 PM 0
Share

$$anonymous$$y basic thinking here is that the get key method is only going to fire if the key is being pressed that frame, I think you should break this function up. there is too much happening in the update function, could you change this code so that there are different functions which each have their own role? $$anonymous$$aybe one function can deter$$anonymous$$e if the key is pressed down and save that as a variable which other functions can reference.

Follow this Question

Answers Answers and Comments

116 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 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 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 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 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 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

Can't seem to get bool/SetActive Script to work 2 Answers

physics.OverlapSphere colliders 1 Answer

Screensaver when device is idle 1 Answer

Click and drag an object if holding a button down. 0 Answers

How can I enable an object in js? 3 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