- Home /
Problem with ArrayList in unity javascript
Hello
I have problem with Line 48 and "Import.System...." in unity javascript this is my code.
import System.Collections.Generic;
var positions : Vector3[] = new Vector3[12];
var prefabs : GameObject[] = new GameObject[12];
var refreshed : boolean;
var twelve_1 : GameObject;
var twelve_2 : GameObject;
var chief_1 : GameObject;
var chief_2 : GameObject;
var countDown : GameObject;
function Start () {
//========================| Set Positions |===========================
positions[0] = new Vector3(-0.191685f,1.202802f,-9.211868f);
positions[1] = new Vector3(-0.3810821f,1.202802f,-9.211868f);
positions[2] = new Vector3(-0.5704792f,1.202802f,-9.211868f);
positions[3] = new Vector3(-0.191685f,1.013408f,-9.211868f);
positions[4] = new Vector3(-0.3810821f,1.013408f,-9.211868f);
positions[5] = new Vector3(-0.5704792f,1.013408f,-9.211868f);
positions[6] = new Vector3(-0.191685f,0.8240138f,-9.211868f);
positions[7] = new Vector3(-0.3810821f,0.8240138f,-9.211868f);
positions[8] = new Vector3(-0.5704792f,0.8240138f,-9.211868f);
positions[9] =new Vector3(-0.191685f,0.6346197f,-9.211868f);
positions[10] =new Vector3(-0.3810821f,0.6346197f,-9.211868f);
positions[11] =new Vector3(-0.5704792f,0.6346197f,-9.211868f);
//Run Replace at start time
Replace();
}
function Update () {
}
function Replace (){
var Prefabs : ArrayList.<GameObject> = new ArrayList.<GameObject>.(prefabs);
while(prefabs.Length > 0){
var ChoosenPosition : int = Random.Range(0 , positions.Length);
var ChoosenPrefab : int = Random.Range(0 , prefabs.Length);
prefabs[ChoosenPrefab].transform.position = positions[ChoosenPosition];
prefabs.Pop();
}
}
function IGReplace (){
}
thanks in advance.
You can't just tell us you have a problem and dump some code. WHAT is the problem? What is the expected results, and what is the result you get?
We can't help you if we don't know the problem.
Also definitely worth pointing out that Java is NOT the same thing as Javascript. They are VERY different languages, and it's best for all concerned if you at least recognise that there is a difference.
Excuse me I'm really sorry about that. $$anonymous$$y main problem is with this line of code:
var Prefabs : ArrayList.<GameObject> = new ArrayList.<GameObject>.(prefabs);
and I couldn't know : is my this line is true?
import System.Collections.Generic;
thanks again
Answer by Eric5h5 · Mar 16, 2014 at 05:04 PM
Not "ArrayList". Just "List".
Ah, can't believe I didn't spot that. ArrayList is Java ter$$anonymous$$ology (not Javascript, actual Java), and the Unity equivalent (based on .NET) is List.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Semi colon placement? unity error message 2 Answers
Ball jumping mechanic, scrip errors. 1 Answer
Acces to a var from another Script. 2 Answers