• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Luuk · May 18, 2013 at 06:23 PM · javascriptclassconstructorargumentmatching

"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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Luuk · May 18, 2013 at 06:39 PM 0
Share

Wauw, can't beleive I missed that. Thanks a bunch!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

14 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Construct class with enum parameter (javascript) 0 Answers

List of Classes (js) - How to Construct Properly 1 Answer

Object reference not set to an instance of an object 1 Answer

Finding the length of an enum in a different class 1 Answer

AndroidJavaObject Builder Class 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges