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();
     }
 }
}
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                