- Home /
java to C#
hi am trying to create a simple GUItexture that will change depending on collision with an item the code in java is: please change to c#
static var Life : int = 0;
var Threelife : Texture2D;
var Twolife : Texture2D;
var Onelife : Texture2D;
var Nolife : Texture2D;
function Start () {
Life = 0;
}
function Update () {
if(Life == 1){
guiTexture.texture = Twolife;
}
else if (Life == 2){
guiTexture.texture = OneLife;
}
else if (Life >= 3) {
guiTexture.texture = NoLife;
}
else {
guiTexture.texture = ThreeLife;
}
}
Answer by rutter · Apr 13, 2012 at 01:10 AM
This looks like an easy script to translate.
//javascript
var Threelife : Texture2D;
//C#
public Texture2D Threelife;
//javascript
function Start() { ... }
//C#
void Start() { ... }
If you're really having that much trouble, this isn't necessarily a good place to learn C# -- luckily there are numerous tutorials around the net that can help you with that.
I agree. Try it for yourself , you will learn to understand both unityscript and C#.
Reference : http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
Online Converter : http://files.m2h.nl//js_to_c.php
Answer by Danpe · Apr 13, 2012 at 01:11 AM
C#
public static int Life = 0;
public Texture2D Threelife, Twolife, Onelife, Nolife;
void Start ()
{
Life = 0;
}
void Update ()
{
if(Life == 1)
{
guiTexture.texture = Twolife;
}
else if (Life == 2)
{
guiTexture.texture = OneLife;
}
else if (Life >= 3)
{
guiTexture.texture = NoLife;
}
else
{
guiTexture.texture = ThreeLife;
}
}
This isn't really C#. First there is no "function" keyword like in Unityscript, second i guess your texture variables should be public. The default visibility in C# is private.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
this script in Javascript?? 0 Answers
Help with conversion from javascript to c# 3 Answers
Can someone help me translate this to c#? 1 Answer
error CS1061 anybody might help me? 1 Answer