Web server is returning an unknown error Error code 520
There is an unknown connection issue between Cloudflare and the origin web server. As a result, the web page can not be displayed.
What can I do?
If you are a visitor of this website:
Please try again in a few minutes.
If you are the owner of this website:
There is an issue between Cloudflare’s cache and your origin web server. Cloudflare monitors for these errors and automatically investigates the cause. To help support the investigation, you can pull the corresponding error log from your web server and submit it our support team. Please include the Ray ID (which is at the bottom of this error page). Additional troubleshooting resources.
Cloudflare Ray ID: 801d9af4649ed56c • Your IP: Click to reveal 86.107.21.84 • Performance & security by Cloudflare
WaitForSeconds
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Suspends the coroutine execution for the given amount of seconds using scaled time.
The real time suspended is equal to the given time divided by Time.timeScale. See WaitForSecondsRealtime if you wish to wait using unscaled time. WaitForSeconds can only be used with a yield statement in coroutines.
There are some factors which can mean the actual amount of time waited does not precisely match the amount of time specified:
1. Start waiting at the end of the current frame. If you start WaitForSeconds with duration ‘t’ in a long frame (for example, one which has a long operation which blocks the main thread such as some synchronous loading), the coroutine will return ‘t’ seconds after the end of the frame, not ‘t’ seconds after it was called.
2. Allow the coroutine to resume on the first frame after ‘t’ seconds has passed, not exactly after ‘t’ seconds has passed.
How to add time delay in Unity C#
So I’m trying to make a camera zoom in, but Thread.Sleep doesn’t work. Here is the code:
The error code is this:
2 Answers 2
You are getting this error message because you are missing a line that accesses the API for this. Simply add using System.Threading; at the top of your script. This will access the API for it. Or use a coroutine, which won’t freeze the entire game as a whole and is a much better alternative, as DMGregory suggested.
An important thing to understand about Unity is that the MonoBehaviour message methods like Start() and Update() are called on the main thread (ie. single-threaded). So if you stall one of them by hitting a long-running loop or sleeping the thread, you cause the entire game to hang.
So, if you want to add a delay, it needs to be by yield ing control back to the engine temporarily — so it can continue running other update functions, accepting input, rendering frames, etc. — until you are ready to resume your work.
![]()
You must log in to answer this question.
-
Featured on Meta
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.9.4.43609
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Как сделать задержку выполнения кода в Unity C#?

не рекомендую делать WaitForSeconds в Update потому что по сути такой код будет начинать каждый тик (Update вызывается 60 вроде бы раз в секунду) новый интервал задержки, и сам Update может встать (или чтото еще в таком духе, надо тестить, вообщем баг явный)
на самом деле такой код может рабоатть, но только для быстрых корутин, не для ожидания 5 сек
аналогично из Start можно запускать корутину с ожиданием
лучше запустить корутину из Start() — пример же в доке есть