- Home /
Error Assets/OrangeSpawnScript.js(4,33): UCE0001: ';' expected.
I'm getting error Assets/OrangeSpawnScript.js(4,33): UCE0001: ';' expected. Insert a semicolon at the end. When there is a Semicolon there already. Not sure what to do been staring at this for hours and can't figure it out. Any Help would be apperciate.
var cubeList : GameObject[];
var randomCube : GameObject = cubeList[(int) (Random.value * cubeList.Length)];
Answer by Landern · Nov 18, 2014 at 04:31 PM
cubeList doesn't have anything initialized even if you are assigning values in the inspector. It's field. The object needs to be created, fields can not assign to fields even though you can visually make an assumption of declaring the field and assigning values to a field. When an object is instantiated the fields come first, this allows them to be available to use in the constructor of a class/object.
update your code to assign in Start()
var cubeList : GameObject[];
var randomCube : GameObject;
function Start() {
randomCube = cubeList[(int) (Random.value * cubeList.Length)];
}
Hey its still giving me the same error thanks for the help I need it.
Your answer
Follow this Question
Related Questions
JavaScript 3 Arrays questions 1 Answer
Array of Arrays of GameObjects/Prefabs (C#) 1 Answer
Is it possible to store variables in arrays? 1 Answer
Destroy created children of objects 1 Answer