Hello,
I’m working on a pong game. I’ve created cubes with textures for powerups, and everything is working ok, except when the cube is instantiated, it is upside down.
Here’s the code for instantiating the powerups:
// Get a random number to determine which powerup will spawn
int powerUp = Random.Range(0,4);
// Random number to determine where powerup will spawn on the x-axis, and -13 to get the range between -13, 13
int xSpawn = Random.Range(0, 27);
xSpawn = xSpawn - 13;
// Random number to determine where powerup will spawn on the y-axis, and -11 to get the range between -10, 12
int ySpawn = Random.Range(0, 23);
ySpawn = ySpawn - 10;
// Spawn powerup
if(powerUp == 0)
{
Instantiate(growPower, new Vector3(xSpawn, ySpawn, 0), Quaternion.identity);
powerUpInPlay = true;
powerUpAppearsIn = powerUpAppearsInReset;
}
The powerup prefab rotation is 0,0,0 and if I just drag one of them in, they appear right way up. I’ve tried changing the rotation of the prefabs transform in the hope that two wrongs will make a right, but they stubbornly spawn upside down. Can anyone help? I suspect the problem is related to Quaternion.identity, but I’m new to unity and still trying to get my head around these concepts.
Another thing I’d like to know is why prefabs are instantiated as transforms, rather than gameobjects?
// PowerUps
public Transform shrinkPower;
public Transform growPower;
public Transform fastPower;
public Transform slowPower;
Thanks in advance!