Hello everybody,
I’m a Java programmer and I’d like to use JavaScript/UnityScript in Unity. I know, there ARE some differences (Java != JavaScript), but the syntax seemed simillar when I had a look at some tutorials.
However, none of the tutorials I came across ever covered the topic of properly declaring a class in Unity. So I tried to do it myself, here’s the result:
public class Card {
public enum Category { CREATURE, EQUIP, ASSIST, ATTACK, TECH, DEFENSE }
// field declarations
protected var cardName : String;
protected var cardCategory : Category;
// constructor declaration
public function Card(cardName : String, cardCategory : Category){
this.cardName = cardName;
this.cardCategory = cardCategory;
}
// public method declaration
public function toString() : String {
return "Card '" + this.cardName + "' [" + this.cardCategory + "]";
}
}
That would be my class declaration. I assigned the following script to an object in my scene:
var tempCard : Card = new Card("SomeCardName", Card.Category.CREATURE);
function Update () {
print(tempCard.toString());
}
… which produced the correct output on the Unity console. So basically - it works.
However, in MonoDevelop, I have no code completion for neither fields/attributes nor functions/methods for the “Card” class - which tells me that apparently I did something wrong (or at least not the way it is supposed to be).
I’d really appreciate it if somebody could tell me if I made a syntax mistake or did something “unusual” in my class declaration above.
Thanks,
Alan47