edx/assignment8final/Assets/Resources/Scripts/GemSpawner.cs

30 lines
691 B
C#
Raw Normal View History

2022-11-10 21:56:29 -03:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GemSpawner : MonoBehaviour
{
public GameObject[] prefabs;
// Start is called before the first frame update
void Start()
{
StartCoroutine(SpawnGem());
}
// Update is called once per frame
void Update()
{
}
IEnumerator SpawnGem() {
while (true) {
GameObject gem = Instantiate(prefabs[Random.Range(0, prefabs.Length)], new Vector3(26, Random.Range(-10, 10), 10), Quaternion.identity);
gem.GetComponent<Renderer>().material.color = Color.red;
yield return new WaitForSeconds(Random.Range(7, 15));
}
}
}