Hi all, im trying to spawn a prefab (successful) at location “spawnpos” (Successful), but make it a child of the parent “Tokens attach” (unsuccessful) as soon as it is spawned. I think ive put the transform.position line in the wrong place maybe but im new so not sure.
here is my script:
public class Spawner : MonoBehaviour
{
public Transform spawnPos;
public GameObject TokenPrefab;
public GameObject Tokensattach;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
Instantiate(TokenPrefab, spawnPos.position, spawnPos.rotation);
}
TokenPrefab.transform.parent = Tokensattach;
}
}
thanks