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
1
Question by HeldomLtd · Aug 11, 2017 at 07:12 PM · wait

Wait for a second without using Coroutine

Hello! I am trying to make a script that allows the player to take a screen shot, then notifies them of it. I have created this script here:

using UnityEngine; using System.Collections; using UnityEngine.UI;

public class ScreenShotScript : MonoBehaviour {

 public Text screenshotText;
 public float textShow = 10f;

 void Start () {
     screenshotText.enabled = false;
 }

 void Update () {
     if(Input.GetButtonDown("Screenshot")) {
         ScreenShot();
     }
 }

 void ScreenShot() {
     Application.CaptureScreenshot ("Screenshot.png");

     screenshotText.enabled = true;
     //Right here is where it would wait for 10 seconds
     screenshotText.enabled = false;


 }

}

The problem is, whenever I try to make it wait so then the players sees the message then it disappears, I get an error trying to use corountine. Is there anyone who can help me? Thanks!

Comment
Add comment · Show 1
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 Chanisco · Aug 11, 2017 at 07:32 PM 0
Share

What error do you get in the for the Coroutine?

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by TwinGhosts · Aug 11, 2017 at 08:00 PM

You need to use an IEnumerator for a coroutine. After that you can use a new yield waitforseconds. This is how the manual handles it.

 using UnityEngine;
 using System.Collections;
 
 public class WaitForSecondsExample : MonoBehaviour
 {
     void Start()
     {
 // Start the coroutine - enter the name of the IEnumerator
         StartCoroutine(Example());
     }
 
     IEnumerator Example()
     {
         // Code before the pause
         yield return new WaitForSeconds( 5 ); // Wait or a number of seconds
         // Code after the pause
     }
 }

Alternatively, you could use Invoke to wait a couple of seconds before calling a Method.

 void Start(){
         Invoke("Screenshot", 5f); // Name of the method and time before it calls
 }
 
 void Screenshot(){
       // Your code which gets called after 5 minutes
 }

Comment
Add comment · 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
-1

Answer by unity_niWqoFh70ON5rg · Mar 18, 2020 at 10:56 AM

Does this work ?

public float wait; private float waitTime;

void Update() { waitTime = Time.time + wait; while (Time.time < waitTime) {} }

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 Bunny83 · Mar 18, 2020 at 11:59 AM 0
Share

No, it does not. Time.time can only change between two frames. This is true for almost all frame dependent data. Even if it would work your application would be locked up during that times. $$anonymous$$ost operating system would report such an application as "not responsive" and might kill / offer to kill it.


What you've posted is not an answer but a question. Next time when you want to ask a question, please Ask a Question ins$$anonymous$$d of writing an Answer.

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

71 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

Related Questions

Quick question about destroying bullets/objects 1 Answer

How do I wait for an object to load before accessing it's information? 1 Answer

WaitForSeconds Problem [C#] 4 Answers

WaitForSeconds Question 2 Answers

is there a way to Web Download Unity faster? 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