43 lines
1.0 KiB
C#
43 lines
1.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class FruitSpawn : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public class fruitprefab
|
|
{
|
|
public string nome;
|
|
public GameObject prefab;
|
|
}
|
|
|
|
public List<fruitprefab> fruits;
|
|
public Transform[] spawnrandom;
|
|
|
|
public float mins = 0.5f;
|
|
public float max = 1f;
|
|
|
|
IEnumerator Spawn()
|
|
{
|
|
while(true)
|
|
{
|
|
float timer = Random.Range(mins, max);
|
|
yield return new WaitForSeconds(.65f);
|
|
int spawnIndex = Random.Range(0, spawnrandom.Length);
|
|
Transform spawnpoint = spawnrandom[spawnIndex];
|
|
|
|
int rand = Random.Range(0, fruits.Count);
|
|
GameObject spawnFruit = Instantiate(fruits[rand].prefab, spawnpoint.position, spawnpoint.rotation);
|
|
|
|
spawnFruit.transform.Find("banana").gameObject.name = fruits[rand].nome;
|
|
|
|
Destroy(spawnFruit, 5f);
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
StartCoroutine(Spawn());
|
|
}
|
|
}
|