Hey guys,
So, I looked at all the examples I could find online, the documentation, watched videos and… I still don’t get it. How does instantiation work - specifically, the method Instantiate()?
This is the code I wrote in my attempt to just make instantiation work on one of my prefabs - I just want to create copies of my CustomerPrefab:
using UnityEngine;
using System.Collections;
public class CustomerScript : MonoBehaviour {
public GameObject CustomerPrefab;
void Update () {
Instantiate (CustomerPrefab, new Vector3(0,0,0), Quaternion.identity);
}
}
This script is attached to my CustomerPrefab and there’s no errors, but it doesn’t do anything. I understand that they would all spawn in the same spot (0, 0, 0) but for now, I can’t even make it spawn one.
So first off - when you make a new GameObject in the top, does it have to refer to the prefab that I want to copy? If not, then how does Instantiate() know which prefab to copy?
And secondly, the first parameter in Instantiate, what is that even? The documentation says “original” and I would assume that means the original GameObject to be Instantiated, right? But how do you make it refer to a prefab and have it create 5 instances of the prefab?
Michael