- Home /
Save Gameobject in Array
Hello everyone, For some reason, saving a gameobject in an array is not working for me. Granted, I have never worked with arrays before, but I can't find what I am doing incorrectly. My code is this:
using UnityEngine;
using System.Collections;
public class createContact : MonoBehaviour {
public GameObject newContact;
public Vector3 NEWcontactSpawn;
public int contactCount;
int i = 0;
public GameObject[] ContactArray;
//declare variables
void Start ()
{
ContactArray [4] = newContact;
}
and I get an error stating that the array index is out of range. The gui array interface in unity says that the array is 0 items long. I am not sure what is wrong here. Thank you for the help. Sincerely, Wolfshadow
Answer by Wolfshadow · Apr 10, 2017 at 02:04 AM
Never mind, problem solved. I had forgotten to edit the GUI in unity interface and click enter.
Your answer
![](https://koobas.hobune.stream/wayback/20220612115057im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What is the best way to instatiate an array of connected GameObjects? 0 Answers
How to randomly spawn three non repeating gameobjects from an array? 2 Answers
Want replace a current object with one inside array the object being replaced with is prefab 1 Answer
How to put gameObjects to the list? 4 Answers
gameObject are not referenced 2 Answers