- Home /
"does not have a visible constructor that matches" while such a constructor exists, what am I missing?
Im getting the error "BCE0024: The type 'unit' does not have a visible constructor that matches the argument list '(UnityEngine.GameObject, float, float, int)'." for the following code:
var attack : float = 1;
var defence : float = 1;
var hitPoints : int = 3;
var unitStats : unit = new unit (gameObject, attack, defence, hitPoints);
With this class-code:
class unit {
var group : GameObject;
var type: GameObject;
var attack : float;
var defence : float;
var hitPoints : int;
var currentHP : float;
var model : GameObject [];
function team(typ : GameObject, att : float, def : float, hp : int){
type = typ;
attack = att;
defence = def;
hitPoints = hp;
currentHP = hp;
}
function team(grp : GameObject, typ : GameObject, att : float, def : float, mod : GameObject[], hp : int){
group = grp;
type = typ;
attack = att;
defence = def;
model = mod;
hitPoints = hp;
currentHP = hp;
}
I have no clue what would be the problem as to me it seems like it would be working match with the first constructor. What am I missing?
Answer by Tomer-Barkan · May 18, 2013 at 06:27 PM
The names of your constructors do not match the name of the class... Typical copy-paste mistake
Change to:
function unit(typ : GameObject, att : float, def : float, hp : int){
type = typ;
attack = att;
defence = def;
hitPoints = hp;
currentHP = hp;
}
function unit(grp : GameObject, typ : GameObject, att : float, def : float, mod : GameObject[], hp : int){
group = grp;
type = typ;
attack = att;
defence = def;
model = mod;
hitPoints = hp;
currentHP = hp;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613102513im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Construct class with enum parameter (javascript) 0 Answers
List of Classes (js) - How to Construct Properly 1 Answer
How to add javascript classes? 1 Answer
Is it possible to create a script dinamic like animation>size controling the Elements variables? 1 Answer
Reading and Storing External Data into Memory (From Text) 1 Answer