- Home /
Using Yield waitforseconds with boo
I've been following the walkerboystudio tutorials, but I decided that I'll try and write everything with Boo instead of unityScript [or JavaScript .. whatever you wanna call it]
in the first lab project , they call a function from inside the update() that contains Yield waitForSeconds() call , when I did that with Boo the whole function doesn't get called here's my both scripts
JavaScript:
var numberOfClicks = 2;
var waitTime = 2.0;
function Start () {
}
function Update () {
if(numberOfClicks <= 0){
var position = Vector3(Random.Range(-7,7),Random.Range(-4,4),0); //random positions between 2 points
respawnTime();
transform.position = position; //set the object hit to this new position
numberOfClicks = 2;
}
}
function respawnTime(){
renderer.enabled = false;
yield WaitForSeconds(waitTime);
renderer.enabled = true;
}
this one works, and the next one is
Boo:
import UnityEngine
import System.Collections
//Enemy Script
class scriptEnemy (MonoBehaviour):
//public variables
public numberOfClicks = 2
public waitTime = 2.0
def Start ():
pass
def Update ():
if(numberOfClicks <= 0):
position = Vector3(Random.Range(-7,7),Random.Range(-4,4),0) //random positions between 2 points
respawnTime()
transform.position = position //set the object hit to this new position
numberOfClicks = 2
def respawnTime() as IEnumerator:
print ("respawn called")
print(Time.time)
renderer.enabled = false
yield WaitForSeconds(waitTime)
renderer.enabled = true
print(Time.time)
This one does nothing , the whole respawnTime function/subroutine/method doesn't get called at all, if I removed the yield line , it gets called fine Any idea why is this happening ?
I'd just like to say wow the first boo question I've seen! Interested to see the answer...
I did try "yield return new WaitForSeconds" before [found that when I was still looking for a solution] and it didn't work .. nothing happened
Answer by Kevin Harris · Sep 02, 2012 at 04:11 AM
In Boo, like C#, you need to use `StartCoroutine()`. The documentation has an example using WaitForSeconds.
Answer by hijinxbassist · Jun 24, 2012 at 10:53 PM
I havent gotten yield to work, but what you can do is just simply say
WaitForSeconds(waitTime)
if you add yield before the WFS call it stops running all the code in that section, i discovered this method while converting my own script to boo
I removed the yield , but it's not executing the wait part .. I get output as
-respawn called
-1.432662
-1.432662
so it's not waiting at all
is the def X()as IEnumerable ?? i have it in my script and it works
def RespawnTime()as IEnumerable:
print(Time.time)
WaitForSeconds(waitTime)
print(Time.time)
I have found co-routines to be very finicky in boo. I remember it took like 5 times of deleting/re-writing the same exact thing and 2 of 3 would not work. Try rewriting the def and see if it works...i know it works in my script with proper output.
Im testing on a boo script in my current project, and it isnt working...lemme test it some more and ill get back to you. Very strange since it works in my other project.
yeah I did have IEnumerable [also tried IEnumerator just like the unity manual suggests] but that didn't work too here's my whole code right now http://pastebin.com/7em4GQ27 and it just prints the time twice , doesn't wait
Your answer
Follow this Question
Related Questions
Why not Boo? 1 Answer
What programming language do I need to learn? 0 Answers
Can I convert unityscript to boo? 0 Answers
Closure does not work in Unity JS functions? 1 Answer
Collide detection with tag [JS] 0 Answers