Answer the question
In order to leave comments, you need to log in
How to make sure that assistants are placed in certain places when buying them in a 2D clicker?
I'm making a clicker with heroes and monsters and I want to make sure that when buying helper heroes, they are placed in a certain place on the screen. I do not know how to write it in the script, except to make their location on the screen random.
Here is my script:
{
GameObject hero = Instantiate(HeroPrefab) as GameObject;
Vector3 heroPos = new Vector3(
Random.Range(3.0f, 9.5f),
Random.Range(-5.39f, -5.39f),
0);
hero.transform.position = heroPos;
}
Answer the question
In order to leave comments, you need to log in
Make some empty GameObjects in advance, in those places where you need to respawn, create an array in the script and throw all GameObjects into it:
When using Instantiate, use a random element from the array:
GameObject hero = Instantiate(HeroPrefab, SpawnPoints[new Random().Next(0, SpawnPoints.Length)].position, Quaternion.identity);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question