im making a movement script that it waits for a random time then changes direction i am using a yield to do the wait but i don’t know how to get it to loop back round and start over agin
// Prints time
print (Time.time);
// wait for random time
yield WaitForSeconds (Random.Range(3, 10));
//gets object to change direction randomly
transform.Rotate(0, Random.Range(0, 360), 0, Space.Self);
what you can do is use SendMessage, in a script like this
function Awake () {
SendMessage("Rotate");
}
function Rotate () {
// Prints time
print (Time.time);
// wait for random time
yield WaitForSeconds (Random.Range(3, 10));
//gets object to change direction randomly
transform.Rotate(0, Random.Range(0, 360), 0, Space.Self);
SendMessage("Recycle");
}
function Recycle () {
SendMessage("Rotate");
}
Using SendMessage to call a function is kind of silly if the function is in the same script, especially since SendMessage can only take one parameter, you are limited to writing functions that only take one parameter. You could just say Rotate() whereever you want to call the function.