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 RUNIC · Dec 21, 2017 at 09:13 PM · unity 5unity 2dguiskingui.label

Disable GUIskin after time,Remove GUISkin after time

Hello,

When I grab my pickup a GUIskin is actvated. Though, I want this GUIskin to be removed shortly after, lets say 1 second.. Right now it's there for like 5 seconds without anything deciding how long it should be there for.

I heard that I should use "Invoke" to do this, but I simply cannot get it to work.

Can anybody, please(!), show me the true way to do this?

This is my current script:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

[ExecuteInEditMode] public class UITextChili : MonoBehaviour {

 [Space(10)]
 [Header("Toggle for the gui on off")]
 public bool GuiOn = false;


 [Space(10)]
 [Header("The text to Display on Trigger")]
 [Tooltip("To edit the look of the text Go to Assets > Create > GUIskin. Add the new Guiskin to the Custom Skin proptery. If you select the GUIskin in your project tab you can now adjust the Label section to change this text")]
 public string Text = "BOOST";

 [Tooltip("This is the window Box's size. It will be mid screen. Add or reduce the X and Y to move the box in Pixels. ")]
 public Rect BoxSize = new Rect(-20, 0, 500, 100);


 [Space(10)]
 [Tooltip("To edit the look of the text Go to Assets > Create > GUIskin. Add the new Guiskin to the Custom Skin proptery. If you select the GUIskin in your project tab you can now adjust the font, colour, size etc of the text")]
 public GUISkin customSkin;



 // if this script is on an object with a collider display the Gui



 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.CompareTag("Player"))
     {
         GuiOn = true;

     }
    
 }

 void OnTriggerExit()
 {
     GuiOn = false;
 }

 void OnGUI()
 {

     if (customSkin != null)
     {
         GUI.skin = customSkin;
     }

     if (GuiOn == true)
     {
         // Make a group on the center of the screen
         GUI.BeginGroup(new Rect((Screen.width - BoxSize.width) / 2, (Screen.height - BoxSize.height) / 2, BoxSize.width, BoxSize.height));
         // All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.

         GUI.Label(BoxSize, Text);

         // End the group we started above. This is very important to remember!
         GUI.EndGroup();

     }



 }

}

,When I grab a pickup a GUIskin is being showed. Right the GUIskin is on my gamescreen for quite some time. Is there any way to disable GUI skin after, lets say, 1second? I heard that I should use the Invoke-function, but I can't get anything to work. Can you please show me how to remove it after 1 sec?

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

[ExecuteInEditMode] public class UITextChili : MonoBehaviour {

 [Space(10)]
 [Header("Toggle for the gui on off")]
 public bool GuiOn = false;


 [Space(10)]
 [Header("The text to Display on Trigger")]
 [Tooltip("To edit the look of the text Go to Assets > Create > GUIskin. Add the new Guiskin to the Custom Skin proptery. If you select the GUIskin in your project tab you can now adjust the Label section to change this text")]
 public string Text = "BOOST";

 [Tooltip("This is the window Box's size. It will be mid screen. Add or reduce the X and Y to move the box in Pixels. ")]
 public Rect BoxSize = new Rect(-20, 0, 500, 100);


 [Space(10)]
 [Tooltip("To edit the look of the text Go to Assets > Create > GUIskin. Add the new Guiskin to the Custom Skin proptery. If you select the GUIskin in your project tab you can now adjust the font, colour, size etc of the text")]
 public GUISkin customSkin;



 // if this script is on an object with a collider display the Gui



 void OnTriggerEnter2D(Collider2D col)
 {
     if (col.CompareTag("Player"))
     {
         GuiOn = true;

     }
    
 }

 void OnTriggerExit()
 {
     GuiOn = false;
 }

 void OnGUI()
 {

     if (customSkin != null)
     {
         GUI.skin = customSkin;
     }

     if (GuiOn == true)
     {
         // Make a group on the center of the screen
         GUI.BeginGroup(new Rect((Screen.width - BoxSize.width) / 2, (Screen.height - BoxSize.height) / 2, BoxSize.width, BoxSize.height));
         // All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.

         GUI.Label(BoxSize, Text);

         // End the group we started above. This is very important to remember!
         GUI.EndGroup();

     }
 }

}

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

0 Replies

· Add your reply
  • Sort: 

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

191 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Sprite Bug when move 1 Answer

High-score Saving Issue 2 Answers

Animations changing due to scaling of character 2d. 0 Answers

How do i make character eyes blink after some seconds have passed? (on 2D sprite) 1 Answer

Is there a way to have an Awake() run every time a scene is loaded. 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