I want to spawn blocks which have a rotation speed after pressing the space button. I don't think the following code works because it is spawning a new GameObject
each time.
public GameObject blockPrefab;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Vector3 randomSpawnPosition = new Vector2(Random.Range(Player.screenHalfWidth, -Player.screenHalfWidth), 0);
Vector3 randomSpawnRotation = new Vector3(0, 0, Random.Range(0, 360));
GameObject block = Instantiate(blockPrefab, randomSpawnPosition, Quaternion.Euler(randomSpawnRotation));
block.transform.parent = transform;
// How do I set a rotation velocity here?
block.transform.Rotate(new Vector3(0, 0, Random.Range(0, 30)* Time.deltaTime), Space.Self);
}
}
I am unsure what to do as all examples say to use Rotate()
but as far as I can tell that will never work in this situation.