Moving from Javascript to C# Error - does not contain a constructor that takes `x' arguments
Hi, so I'm attempting to replicate an earlier code of mine which was written in Javascript, but I now wish to reuse it in a c# project. Unfortunately I'm getting the error :
error CS1729: The type ToolsHandler' does not contain a constructor that takes
1' arguments
this is driving me nuts and I'm sure it has something to do with me incorrectly translating the code, b ut I can't pinpoint where I've gone wrong.
Here is the constructor/ enum class
using UnityEngine; using System.Collections;
public class ToolsHandler : MonoBehaviour {
public enum ToolType {
GrabArm,
Drill,
StorageEnergy,
StorageMaterials,
}
int toolID; // the ID tag of the item
string toolName; // the escription of the item
ToolType toolType; // the type of item
GameObject toolObj;
// the basic constructor for the tool
public void ToolHandler( int ID, string name ){
toolID = ID;
toolName = name;
}
}
and here is the list class
using UnityEngine; using System.Collections.Generic;
public class ToolList : MonoBehaviour { public GameObject emptyObject;
List<ToolsHandler> toolsList = new List<ToolsHandler>();
void Awake () {
toolsList.Add (new ToolsHandler (01, "name"));
}
}
Also, if anyone can give me any tips on how to format my posts correctly, that would be appreciated too!
Answer by tanoshimi · Feb 27, 2016 at 10:47 PM
That's because your constructor method (line 13) is mis-named ToolHandler. The class is called ToolsHandler. With an 's'...
Right, that's the reason for the error. However there seems to be a conceptional error as well. Since "ToolsHandler" is derived from $$anonymous$$onoBehaviour it shouldn't contain a constructor at all and if than only a parameterless constructor. I guess that class shouldn't be derived from $$anonymous$$onoBehaviour.
Your answer
