- Home /
Declare new class[].vector3[] length?
I have many arrays of Vector3's that represent many shapes, each shape is an arrays of dots:
class Dots
{
var name : String;
var dotarray: Vector3[];
}
var shape : Dots[];
shape =new Dots[10];//10 shapes
for (var j:int = 0; j < 10; j ++){
shape[j]=new Vector3[20];//20 dots per shape... this line crashes
}
BCE0022: Cannot convert 'UnityEngine.Vector3[]' to 'Dots'.
then i am supposed to access it in this way:
var a_dot = shapej[shapeNumber].dotarray[dotNumber]
hi, sorry that's just the total number of dots for every shape / each dotarray, i ll update question sry.
When you want to create 20 dots per shape. Do you mean you want 20 points in space, as in 20 Vector3 objects? In that case you probably want to make an array of vector points. This question may be of help to you http://answers.unity3d.com/questions/673691/declare-new-classvector3-length.html
Thankyou Simon. I wish to have many shapes of each 20 dots, so that i can access the dot array from any shape using a shape array. The question that you referenced is the same page as this one.
Answer by trololo · Mar 26, 2014 at 01:31 PM
Array length = 10, iteration number = 20 : problem.
Thanks alot, you are right about that. It would have said "array out of range" I made a mistake in example code. With correct numbers this is the error:
BCE0022: Cannot convert 'UnityEngine.Vector3[]' to 'Dots'.
Well this is logic, it's not the same type! (as it's said)
class Dots
{
var name : String;
var dotarray: Vector3[];
public Dots(var n : String, var d: Vector3[])
{
name = n;
dotarray = d;
}
}
// ...
for(...)
shape[i] = new Dots("lol", new Vector3[20]);
Brilliant Trololo, that's nice. There's a classes tutorial video from Unity, i hadn't totally figured it out still. Thank You.
here is more formal .JS code:
class Dots
{
var dotarray: Vector3[];
public function Dots( d: Vector3[])
{
dotarray = d;
}
}
var shape : Dots[];
shape =new Dots[10];//10 shapes
for (var j:int = 0; j < 10; j ++){
shape[j]= new Dots(new Vector3[20]);
}
shape[3].dotarray[4]= Vector3.up; // a test line
Answer by diegzumillo · Mar 26, 2014 at 01:47 PM
There are only 10 shapes, so your for loop should be up tp 10, not 20. Also, you want shape[j].dotarray =new Vector3[20]; You already initialized shape in a previous line, inside the for loop you want to initialize the dotarray of each shape.
Your answer
Follow this Question
Related Questions
"Null Reference Error" when using a custom class as an array 1 Answer
Creating a class wide array (c#) 1 Answer
Resizable Array of Classes? 2 Answers
Need help setting an array of my class 0 Answers
Why cant i do this with an array? 1 Answer