|
Just out of curiosity (I'm learning yield and unity scripting), would it be possible to implement WaitForSeconds in Javascript? How would you do it? What about C#? EDIT: Ok, it seems I didn't express myself correctly. My question is hypothetical, let's say you didn't have the WaitForSeconds class available and you needed to create it from scratch. How would you program a class that had the same behavior as the class provided by Unity?
(comments are locked)
|
|
In Javascript:
In C#:
Alternately (Javascript): @ Eruc5h5 Thanks brother it's perfect Solution, I am facing issue with WaitForSecond when Time.timeScale set to 0, i tried lot of same kind solution but all are incomplete... I have invested more-then 6 developing hour to find the solution every time I got Back with function when i tried to made it reusable as you made, cos every time I use it without StartCorroutine With solution you provided I feel relax now and invest my developing hour in real world developing . Thanks Again brother
Jan 05 at 11:40 AM
PAHeartBeat
(comments are locked)
|
|
javascript
in C# you should add System.Collections to your namespaces. also you define a coroutine by returning an IEnumerator.
2f or 2.5f means that the number is a float and not a double or int. you should return an instance of WaitForSecond in C#. see this pages for more info. http://unity3d.com/support/documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html My question is not how to use it. My question is an hypothetical one: Let's say you didn't have WaitForSeconds already available, how would you implement the same function? i.e. How would you create the class WaitForSeconds yourself?
Mar 02 '10 at 11:49 PM
Ezequiel
(comments are locked)
|
|
just put this in the function where ever you need it to stop for a while: yield WaitForSeconds(4); //4 being the number of seconds you want My question is not how to use it. My question is an hypothetical one: Let's say you didn't have WaitForSeconds already available, how would you implement the same function? i.e. How would you create the class WaitForSeconds yourself?
Mar 02 '10 at 11:49 PM
Ezequiel
(comments are locked)
|

I'd suggest reading the documentation, which uses Javascript for all the code examples, and C# where there are significant differences.
I think I've been misunderstood. I'm not asking how to USE WaitForSeconds. I'm asking: If you didn't have WaitForSeconds already implemented, how would you program it from scratch?