• 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 Zariyda · Jan 15, 2014 at 06:17 AM · yieldwaitforsecondsseconds

How to hide cursor for amount of time?

I want to hide the cursor for 4 seconds and show it back, because my main menu has a fade out intro and I don't want to show the cursor when the screen is still black. Thanks for any help. I'm new to code. Doesn't matter if is javaScript or C#.

Comment
Add comment · Show 2
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 DaveA · Jan 15, 2014 at 07:16 AM 0
Share

How do you want to trigger this hiding?

avatar image Zariyda · Jan 15, 2014 at 12:38 PM 0
Share

From beggining of the scene. Should be in void Start(){} I believe.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JoaoOliveira · Jan 15, 2014 at 12:52 PM

How about this?

 public float HideTime;
 
 void Start() {
     Screen.showCursor = false;
     StartCoroutine(ShowCursorAfter(HideTime));
 }
 
 IEnumerator ShowCursorAfter(float hideTime) {
     yield return new WaitForSeconds(hideTime);
     Screen.showCursor = 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 Zariyda · Jan 15, 2014 at 01:12 PM 0
Share

IT WOR$$anonymous$$ED! Thank you, this effect is really useful. And thank you Quillicit as well.

avatar image JoaoOliveira · Jan 15, 2014 at 02:25 PM 0
Share

No problem man, here's more info on Coroutines, they are really useful in Unity.

avatar image
1

Answer by Quillicit · Jan 15, 2014 at 07:19 AM

You could probably create a variable and set it equal to Time.time, then have the cursor come back when Time.time equals the variable plus 4. So something like this should get you started (C#):

 Screen.showCursor = false;
 
 private float momentFadeStart = Time.time;
 
 if(momentFadeStart >= Time.time + 4){
     Screen.showCursor = 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 Zariyda · Jan 15, 2014 at 01:00 PM 0
Share

I'm not sure what I do wrong. I declare the float and I put the statement in the void Start, because I felt it was the case. But it says: "get_time can only be called from the main thread. Constructors and field initializers will be executed from the loading thread when loading a scene. Don't use this function in the constructor or field initializers, ins$$anonymous$$d move initialization code to the Awake or Start function."

So I movie everything up the void Start just below the float, like you wrote. But it gives me a parse error, saying unexpected + and =.

   using UnityEngine;
   using System.Collections;
 
   public class CursorIntro : $$anonymous$$onoBehaviour {   
     private float momentFadeStart = Time.time;
      
 
 
     void Start () { //If I call it Awake, won't fix anything.
         Screen.showCursor = false;
         
      if(momentFadeStart >= Time.time + 4)
             {
         Screen.showCursor = true;
             }
     } 
     
 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Why Is yield return new WaitForSeconds() not working 2 Answers

Definition of Script.function() depends on Script.function()... 3 Answers

Using Yield Wait for seconds with instantiate 1 Answer

Yield waitforseconds not consistent for animation-unity2D 0 Answers

Script gets stuck on WaitForSeconds() 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