Y
Y
Yugg02020-05-03 17:41:47
C++ / C#
Yugg0, 2020-05-03 17:41:47

How can I make a method run multiple times?

You need to make the method work X times.

float x; // переменная (количество, который должен столько раз срабатывать метод)
    public GameObject prefabsY; // Префаб объекта, который хочу заспавнить. 

    void Start()
    {
        SpawnObjectY();
    }

    void SpawnObjectY()
   {
        Instantiate(prefabsY);
   }


I can use: Instantiate(prefabsY); Instantiate(prefabsY); ... Instantiate(prefabsY);
But the numbers can be more than 2 digits.
And for the future it will be useful to know this.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2020-05-03
@YugGO

Cycle, right?

for (int i=0;i<x;i++)
{
SpawnObjectY();
}

Survived... Learn seasharp first! Don't mess with the unit!
And yes, quantity is NEVER float,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question