I’m trying to make a script for a chain, which spawns a certain amount of chain links based on a variable in the inspector. I can not figure out why my code will not instantiate more than one link. I have verified that my loop runs the correct number of times when I remove the instantiate line. Here is my code:
private void Start()
{
for (int numOfChainsToSpawn = 0; numOfChainsToSpawn != numOfChains; numOfChainsToSpawn++)
{
chains[numOfChainsToSpawn] = Instantiate(chainLink, transform.position, transform.rotation);
}
}
Every time I run the Project, it instantiates one link, then I get a nullReference exception. Any ideas on what could be causing this?