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 /
avatar image
0
Question by sampenketh1 · May 31, 2018 at 02:57 PM · unity 5timeimagespacebar

i am trying to deactivate an image for 5 second then make it reappear when the space bar is pressed can anyone help,I am trying to deactivate an image for 5 seconds when I press the space bar and anyone help

this is what i got so far using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Hint : MonoBehaviour {

 public GameObject TextObj;
 float TmStart;
 public float TmLen = 5f;

 // Use this for initialization
 void Start()
 {
     TmStart = Time.time;
 }

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {

         TextObj.SetActive(false).TmLen;
     }
 }

}

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MT369MT · May 31, 2018 at 03:16 PM

Hi, Do you want to make it reappear after 5 seconds or if you press the space bar? Anyway you can try this:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Hint : MonoBehaviour {
 
     public GameObject TextObj;
     float TmStart;
     public float TmLen = 5f;
     // Use this for initialization
     void Start()
     {
         TmStart = Time.time;
     }
     // Update is called once per frame
     void Update()
     {
         if (Input.GetKeyDown("space") && TextObj.activeSelf == true)
         {
             TextObj.SetActive(false);
             StartCoroutine(Hide(TmLen));
         }
     }
 
     IEnumerator Hide(float TmLen)
     {
         yield return new WaitForSeconds(TmLen);
         TextObj.SetActive(true);
     }
 }
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 hawksandwichgames · May 31, 2018 at 05:13 PM 0
Share

Hey, not here to help (sorry) I just wanted to ask what TmStart is used for and why you set it to Time.time. Does it keep something from breaking or did you just accidentally put it in there?

avatar image sampenketh1 hawksandwichgames · May 31, 2018 at 05:20 PM 0
Share

no, I copied someone's else's script and tried to modify it (badly)

avatar image
0

Answer by sampenketh1 · May 31, 2018 at 03:28 PM

sorry didn't make it clear when you press the spacebar it deactivates the image for 5 seconds @MT369MT

Comment
Add comment · Show 4 · 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 MT369MT · May 31, 2018 at 04:51 PM 0
Share

Then the code that I posted should be right. Test it and say if it works.

avatar image sampenketh1 · May 31, 2018 at 05:09 PM 0
Share

it makes the image deactivate but it doesn't reappear

avatar image MT369MT · May 31, 2018 at 05:50 PM 0
Share

Where did you attach your script? At the same object that you will make diseappear? Note that if you use .SetActive(false) on an object all components on that object will be disabled and also all script attached on that object won't run anymore.

avatar image sampenketh1 MT369MT · May 31, 2018 at 06:55 PM 0
Share

thanks, I attached it to the canvas the image was on, and it worked

avatar image
0

Answer by thekinghamza · May 31, 2018 at 05:53 PM

      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      
      public class Hint : MonoBehaviour {
      // if there is a typing error Sorry I didnt write this in VS and if there is a problem with the script add a coment
          public GameObject TextObj;
          float TmStart;
          public float TmLen = 5f;
          private Renderer rend;
          // Use this for initialization
          void Start()
          {
              TmStart = Time.time;
              rend = TextObj.GetComponent<Renderer>();

          }
          // Update is called once per frame
          void Update()
          {
              if (Input.GetKeyDown("space") && rend.enabled== true)
              {
                  StartCoroutine(Hide(TmLen));
              }
          }
      
          IEnumerator Hide(float TmLen)
          {
              rend.enabled = false;
              yield return new WaitForSeconds(TmLen);
              rend.enabled = true;`
          }
      }




Comment
Add comment · Show 1 · 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 thekinghamza · May 31, 2018 at 05:55 PM 0
Share

you can put this on the object that you want to dissapear or not

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

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

UI Collision Detection 0 Answers

Find one image into another image 1 Answer

I have overrided a built-in script accidentally and not sure how to fix 2 Answers

Image Filling To Obtain Color Scale 0 Answers

Time Code Web Camera Image Capture 1 Answer


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