function Start() and class in class

Hi,

I’m new in unity3d and i’m doing something wrong. How to use class in class? I write code like this and i can’t initiate class Player with values in Stat class fields.

var player : Player;

class Stat{
	var current: int;
	var max: int;
}

class Player{
	var name: String;
	var hp: Stat;
	var mana: Stat;
	
	var attack: int;
	var defense: int;
	
	function Player(name: String, hp: int, hpMax: int, mana: int, manaMax: int, attack: int, defense: int){
		this.name = name;
		this.attack = attack;
		this.defense = defense;
		
		this.hp.current = hp;
		this.hp.max = hpMax;
		
		this.mana.current = mana;
		this.mana.max = manaMax;
	}
}

function Start(){
	
	player = new Player("PlayerName", 10, 20, 10, 20, 99, 99);
}

How to set values to hp.max, hp.current, mana.max and mana.current?
How to do it right?

You need to create a new instance of the class before you can use it; by default it is null. In the same way that you’re creating a new instance of Player when you make the player variable.

You need to make these variables public or make new methods for changing their values.
Take a look at public keyword on wikipedia: Java Programming/Keywords/public - Wikibooks, open books for an open world

This is “basic programming stuff” and you’ll probably use this in every script you write.

function Start(){
player = new Player(); // You need to Make a new Instance of the class before assigning values to it =)
player = new Player(“PlayerName”, 10, 20, 10, 20, 99, 99);
}