- Home /
Answer by Josh1231 · Nov 03, 2013 at 02:39 AM
// C#
randnumb = Random.Range (1,10)
for (int i = 0; i < randnumb; i++)
// i don't actually know javascript so i'm guessing it will be one of these two
randnumb = Random.Range (1,10)
for (i=0;i < randnumb; i += 1)
//or
randnumb = Random.Range (1,10)
for (var i=0; i < randnumb; i += 1)
No appropriate version of 'UnityEngine.$$anonymous$$onoBehaviour.StartCoroutine' for the argument list '(int)' was found.
This has happened no matter what I try.
$$anonymous$$y bad I accidentally was using a Coroutine which was not working. But either way nothing spawned.
Wait hold on I was being dumb and was not using the right function. Thanks!
On a side note, anyone know how to generate random noise and applying it to an object?
Answer by clunk47 · Nov 03, 2013 at 02:43 AM
You didn't specify, so I'll give you a C# example of how to use a Coroutine to do this.
using UnityEngine;
using System.Collections;
public class LoopTest : MonoBehaviour
{
int loops;
int count = 0;
IEnumerator Start()
{
loops = Random.Range (5, 25);
while(true)
{
count++;
print (count+" of "+loops+"loops completed.");
if(count == loops)
{
print ("Loop finished.");
StopAllCoroutines();
}
yield return new WaitForSeconds(0.5f);
}
}
}
Javascript. Sorry next time I'll be sure to list what I am familiar with.
Your answer
Follow this Question
Related Questions
Repeat Function 1 Answer
Edit - Code isolation using random ID numbers C# 1 Answer
Spawning an object at a random time | C# 2 Answers
Decrease a value over time? 2 Answers
Assigning random numbers to variables in the awake function 1 Answer