UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"Spawn a prefab in parent position when Z key si pressed"
using UnityEngine; public class SpawnPrefab : MonoBehaviour { public GameObject prefab; public Transform parentTransform; // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Z)) { Spawn(); } } void Spawn() { GameObject spawnedPrefab = Instantiate(prefab, parentTransform.position, Quaternion.identity); spawnedPrefab.transform.SetParent(parentTransform); } }