Hi guys, i have a problem with a code, practically when i press the button " create " i should print some information, but it's like my code cannot find those information.
Here's a code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class CreateNewCharacter : MonoBehaviour {
private BasePlayer newPlayer;
private string playerName = "Enter Name";
Text charText;
private bool soldier = true;
private bool pilot;
private bool citizen;
private bool create;
void Awake(){
}
void Start () {
}
void Update () {
}
void OnGUI()
{
create = GUI.Button(new Rect((Screen.width/2),(Screen.height/2)+25,100,20),"Create");
playerName = GUI.TextArea(new Rect((Screen.width/2)-100,(Screen.height/2)-25,200,25),playerName ,15);
if (GUI.Toggle(new Rect((Screen.width/2)-100,(Screen.height/2),100,20),soldier, "Soldier")) {
soldier = true;
pilot = false;
citizen = false;
}
if (GUI.Toggle(new Rect((Screen.width/2)-100,(Screen.height/2)+25,100,20),pilot, "Pilot")) {
pilot = true;
soldier = false;
citizen = false;
}
if (GUI.Toggle(new Rect((Screen.width/2)-100,(Screen.height/2)+50,100,20),citizen, "Citizen")) {
pilot = false;
soldier = false;
citizen = true;
}
if (create == true){
Debug.Log("Button was pressed");
if(soldier){
newPlayer.PlayerClass = new BaseSoldierClass();
}else if(pilot){
newPlayer.PlayerClass = new BasePilotClass();
}else if(citizen){
newPlayer.PlayerClass = new BaseCitizenClass();
}
newPlayer.PlayerLevel = 1;
newPlayer.Stamina = newPlayer.PlayerClass.Stamina;
newPlayer.Velocity = newPlayer.PlayerClass.Velocity;
newPlayer.Intellect = newPlayer.PlayerClass.Intellect;
newPlayer.Strength = newPlayer.PlayerClass.Strength;
newPlayer.Observation = newPlayer.PlayerClass.Observation;
newPlayer.Luck = newPlayer.PlayerClass.Luck;
newPlayer.PlayerName = playerName;
Debug.Log("Player Name : " + newPlayer.PlayerName);
Debug.Log("Player Class : " + newPlayer.PlayerClass.CharacterClassName);
Debug.Log("Player Level : " + newPlayer.PlayerLevel);
Debug.Log("Player Stamina : " + newPlayer.Stamina);
Debug.Log("Player Velocity : " + newPlayer.Velocity);
Debug.Log("Player Intellect : " + newPlayer.Intellect);
Debug.Log("Player Strength : " + newPlayer.Strength);
Debug.Log("Player Observation : " + newPlayer.Observation);
Debug.Log("Player Luck : " + newPlayer.Luck);
Application.LoadLevel("Scene2");
}
using UnityEngine;
using System.Collections;
public class BaseSoldierClass : BaseCharacterClass {
public BaseSoldierClass() {
CharacterClassName = "Soldato";
CharacterClassDescription = "E' un soldato addestrato per combattere i gay";
Stamina = 15;
Velocity = 15;
Strength = 20;
Intellect = 10;
Observation = 10;
Luck = 10;
}
}
someone know how to fix it? the error is this one
NullReferenceException: Object reference not set to an instance of an object
CreateNewCharacter.OnGUI () (at Assets/Scripts/CreateNewCharacter.cs:61)