You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
790 B
C#
27 lines
790 B
C#
6 months ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Autohand.Demo{
|
||
|
public class TomatoSpawner : MonoBehaviour{
|
||
|
public GameObject[] tomatoes;
|
||
|
List<GameObject> copies;
|
||
|
|
||
|
void Start(){
|
||
|
copies = new List<GameObject>();
|
||
|
foreach(var tomato in tomatoes) {
|
||
|
var newTomato = Instantiate(tomato, tomato.transform.position, tomato.transform.rotation);
|
||
|
newTomato.transform.position += new Vector3(0, 0.2f, 0);
|
||
|
newTomato.SetActive(false);
|
||
|
copies.Add(newTomato);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void SpawnTomato() {
|
||
|
int i = Random.Range(0, copies.Count-1);
|
||
|
Instantiate(copies[i], copies[i].transform.position, copies[i].transform.rotation).SetActive(true);
|
||
|
}
|
||
|
}
|
||
|
}
|