- Home /
convert to c#
hi for everyone! i have some question about c#.
here is script in js Test1.js
#pragma strict class Test2 extends System.Object { var var1 = 1; var var2 = 2; } var testVar : Test2;
in hierarchy it's view on game object as testVar - var1 - var2
i have a problem when a want to write such as in c#. please, help me, how can i get it in c#? sorry for my english.
Answer by IndieScapeGames · Aug 02, 2012 at 03:35 PM
class Test2 {
public Test2() {
}
int var1 = 1;
int var2 = 2;
void Start() {
Test2 newVar = new Test2();
}
void Update() {
}
}
If you want to pass var1 and var2 as parameters for the Test2 object, make the constructor with the 2 parameters in the parenthesis.
public Test2(int var1, int var2) {
this.var1 = var1;
this.var2 = var2;
}
Answer by allashremoter · Aug 02, 2012 at 09:04 PM
Thank you very much! But this is not what i want. Here is a right solution: class Test1 : MonoBehaviour { [System.Serializable] public class Test2 { public int var1 = 1; public int var2 = 2; }
public Test2 var3;
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Converting JS to C# 3 Answers
C# to UnityScript conversion help. 0 Answers
Convert Network.ViewID to Int 1 Answer