Skip to content

Instantly share code, notes, and snippets.

@aprilspeight
Created July 18, 2022 21:23
Show Gist options
  • Save aprilspeight/b28cc57010454184411795786c46dc9e to your computer and use it in GitHub Desktop.
Save aprilspeight/b28cc57010454184411795786c46dc9e to your computer and use it in GitHub Desktop.
Instantiate a prefab on key press.
// Assign the prefab in the editor
public GameObject prefab;
void Update()
{
// Spawns a prefab when a key is pressed
if (Input.GetKeyDown("space"))
{
Instantiate(prefab);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment