Hello,
I’m making 2D RPG game. I made script that is used for Levels, Health, Mana, Strenght etc.
public class mainClass {
private string _Imie;
public int _LVL;
public int _HP;
public int _MP;
public mainClass(){
_Imie = string.Empty;
_LVL = 1;
_HP = 100;
_MP = 100;
}
public string Imie
{
get{ return _Imie; }
set{ _Imie = value; }
}
public int Level
{
get{ return _LVL; }
set{ _LVL = value; }
}
public int Health
{
get{ return _HP; }
set{ _HP = value; }
}
public int Mana
{
get{ return _MP; }
set{ _MP = value; }
}
}
And when I want to use it while fighting scene is played, Unity crashes.
Here is script that cause crash.
using UnityEngine;
using System.Collections;
public class GUIfight : MonoBehaviour {
private mainClass _Hero = new mainClass();
public GUISkin gSkin;
void OnGUI()
{
GUI.skin = gSkin;
GUI.Box(new Rect(Screen.width/2 - 500, Screen.height/2 + 200, 100, 100), "\n\n\n\n\t");
GUILayout.BeginArea(new Rect(Screen.width/2 - 500, Screen.height/2 + 200, 100, 100));
GUILayout.Label(" Level " + _Hero.Level);
GUILayout.Label(" HP " + _Hero.Health);
GUILayout.Label(" MP " + _Hero.Mana);
GUILayout.EndArea();
}
}
If I remove private mainClass _Hero = new mainClass(); then everything works fine.