Recently I have been coding a game that requires you to pick up collectibles across a map. As I am fairly new to c#, I really can’t work it out and i cant get the objects to distribute. Also having some trouble with quaternions. I would really appreciate some help. It’s made in top down 2D.
code:
public Object Wood;
public Transform WoodP;
public Vector3 woodpos = new Vector3(Random.Range(100, -100), Random.Range(100, -100), 0);
void Update()
{
Instantiate(Wood, woodpos, Quaternion.Euler(Random.Range(0, 360), 0, 0), WoodP);
}
So I did that (minus the rotation) and it completely bugs out spawning massive objects, and crashing the game (not sure how big they are, could just be a visual glitch)
Code:
public Object Wood;
public Transform WoodP;
public int Spawncount = 5;
int spawnLimit = 0;
public void Update()
{
if (spawnLimit != Spawncount || spawnLimit <= Spawncount)
{
WoodGen();
spawnLimit++;
}
}
void WoodGen()
{
Vector3 woodpos = new Vector3(Random.Range(100, -100), Random.Range(100, -100), 0);
Instantiate(Wood, woodpos, Quaternion.Euler(Random.Range(0, 360), 0, 0), WoodP);
}
}