Hi! I’m trying to create script to randomly spawns object using coroutine from the video tutorial i found on youtube:
I follows the steps but using different variable names, but i got some error that doesn’t exist in the video (shown in the picture below) what should i do to fix this? and below i also paste my code
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour, TimedInputHandler
{
public GameObject[ ] sampah;
public Vector3 spawnRange;
private int randSampah;
private int trashCount=0;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void HandleTimedInput()
{
IEnumerator nyampah()
{
yield return new WaitForSeconds(1);
while(trashCount<11)
{
yes it’s the implemented interface, but when i changed the void into IEnumerator, some more error pops up.
but after consulting with a lab assistant from my college i found out that i forgot that the coroutine is a function, and i can’t make a function within a function, that was pretty dumb of me haha. that trashCount was my own code to stop the loop
anyway, thanks for your reply!