- Home /
The question is answered, right answer was accepted
JS to C# class conversion issue.
In US I had a HandGun class with properties that had no value, and then a Gun class that defined all of those values by programming:
HandGun.js
class HandGun
{
var name : String;
var ammoType : String;
}
M9.js
class M9 = new HandGun();
M9.name = "M9"'
M9.ammoType = "9mm";
and there are no errors. (I typed that up now so please excuse any errors)
But I am porting the code to C# and I have:
HandGun.cs
public class HandGun : MonoBehaviour
{
public string name;
public string gunID;
}
M9.cs
public class M9 : MonoBehaviour {
public HandGun M9 = new HandGun();
M9.name = "M9";
M9.gunID = "M9";
}
And i just cant find a way to replicate the effect. What am I doing wrong?
Answer by tw1st3d · Aug 02, 2013 at 04:08 AM
public class HandGun : MonoBehaviour
{
to
public class HandGun : Component
{
or remove the type all together. MonoBehaviors are meant to be set onto objects as GameComponents, and can not be defined as "new"