Hi, i have a question. how can i convert a JavaScript (or UnityScript for the community)
to a C# script. This is the code i use to make my floor.
var block : GameObject;
//Change to adjust the lenght = x and z
var worldWidth : uint = 20;
var worldHeight : uint = 20;
function Start () {
CreateWorld();
}
function Update () {
}
function CreateWorld() {
//Space between each block (x)
for(var x : uint =0; x<worldWidth; x+=1) {
//Space between each block (z)
for(var z : uint =0; z<worldHeight; z+=1) {
var block = Instantiate(block);
block.transform.position = new Vector3(this.transform.position.x + x, this.transform.position.y, this.transform.position.z + z);
}
}
}
So, what do i have to change in the script to let this script to be a C#.
I use this script to create a 20 by 20 grid out of cubes. But i wish to have this script to be C#, because some people said to me that C# runs faster most of the time.
And how do i add it so i can change the Width from x and z in the inspector?
Thanks for reading all this and i hope you can help me out.
Yeah right, so i understand everything in the script but i don't know why "FIXME_VAR_TYPE" is in the script. In JavaScript was var, but i have no clue what it could be in C#. I'm missing a cast on that part.
– HexerWell you can just delete it and with instantiate you could mention the path for instantiate your asset. the var block and already been defined globally as gameobject block. If you found this answer helpful kindly mark it.
– Karsnen_2Thanks for sharing the links Alucardj, I will try my best to learn and understand both language.
– Hexer@alucardj Well he wanted to convert from unityscript to c#. When the question so concerned to one point & I found a resource available, I think it is useful. Unity offers both c# and Unityscript. Sometimes you tend to end up with a script on another language where you have no experience. But you might be really good in other. If that is the case, then I would mind converting the script and tinkering it, rather than learning something which would end up as time wasted from my pocket.
– Karsnen_2You have a point, I agree with that and your case is inspiring too. I never meant completely that learning a new language is a waste of time. For me, I am so found of C# after I made a switch from Javascript. Then when I see certain script in Javascript which I want it in C#, I kinda feel the need of the convertor for ease of my tasks and concentrate where I need to devote my time - which is in fact developing the product which I want to. Why do you feel C++ might fade away? Very interesting.
– Karsnen_2