Hello, Unity forums. I am having bit of a trouble trying to instantiate a prefab into the scene after a certain time interval.
My script is as follows:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RainAppear : MonoBehaviour {
//public float waitForRain;
public Transform rainPrefab;
float waitTime;
void Awake()
{
waitTime = Random.Range(0.0f, 4.0f);
}
IEnumerator showRain()
{
yield return new WaitForSeconds(waitTime);
Instantiate(rainPrefab, new Vector2 (0f,Random.Range(0.0f, 3.5f)) , Quaternion.identity);
}
void Start()
{
StartCoroutine(showRain());
}
}
What am I doing wrong?
I am a newbie to Unity and C#, so some help would be really appreciated, thank you.