SpawnPrefabOnKeyDown.cs 303 B

12345678910111213
  1. using UnityEngine;
  2. public class SpawnPrefabOnKeyDown : MonoBehaviour
  3. {
  4. public GameObject m_Prefab;
  5. public KeyCode m_KeyCode;
  6. void Update()
  7. {
  8. if (Input.GetKeyDown(m_KeyCode) && m_Prefab != null)
  9. Instantiate(m_Prefab, transform.position, transform.rotation);
  10. }
  11. }