Untitled

 avatar
unknown
c_cpp
3 years ago
1.3 kB
7
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class producesphere : MonoBehaviour
{
    public timer timer;
    public Transform[] pos;
    public GameObject sphere;
    public GameObject Errorsphere;
    // Start is called before the first frame update
    void Start()
    {
        timer = GameObject.Find("Time").GetComponent<timer>();
    }

    // Update is called once per frame
    void Update()
    {
        if(timer.IsGameOver)
        {
            CancelInvoke();
        }
    }

    private void MakeSphere()
    {
        int random = Random.Range(0, 10);
        do
        {
            random = Random.Range(0, 10);
        } while (pos[random].childCount >= 1);

        Instantiate(sphere, pos[random]);
    }

    private void MakeErrorSphere()
    {
        int random = Random.Range(0, 10);
        do
        {
            random = Random.Range(0, 10);
        } while (pos[random].childCount >= 1);

        Instantiate(Errorsphere, pos[random]);
    }

    public void Diff1()
    {
        InvokeRepeating("MakeSphere", 0, 1);
    }

    public void Diff2()
    {
        InvokeRepeating("MakeSphere", 0, 1);
        InvokeRepeating("MakeErrorSphere", 3, 3);
    }
}