- Home /
Question by
AwesomestMason · Feb 03, 2015 at 05:23 AM ·
javascriptconstructors
The type 'WorldPosition' does not have a visible constructor that matches the argument list '(int, int)'.
WorldPosition.js
private var x : int;
private var y : int;
public function WorldPosition(x1 : int, y1 : int){
x=x1;
y=y1;
}
function getX() : int {
return x;
}
function getY() : int {
return y;
}
function setX(x1 : int) {
x =x1;
}
function setY(x1 : int) {
y =x1;
}
Now when I run this from another script, I get an error.
tiles.Add(WorldPosition(position.getX()+i, position.getY()+i2));
Comment
I think its a type mismatch.WorldPosition(x1,y1) where x1 and y1 are integer arguments.But the value you pass from position.getX() and position.getY() might contain floating point values.
Your question is "How do I declare a constructor in JavaScript for Unity".
I don't know the answer, I'm a C# man, but this may help your googling.
Your answer
![](https://koobas.hobune.stream/wayback/20220613182310im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
How to make a List Constructor? 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Collision wont be detected 1 Answer
Move object to raycast point. 3 Answers