Been following along with a tutorial on YouTube by a guy named HardlyBriefDan. He’s doing a tutorial on how to create a basic RPG game. The guy seems to know what he’s doing and I’m right there with him doing all he does, but I’m getting an error. I tried posting on the video page, messaging the guy directly, but not getting any help. Was suggested I ask here, so here it is.
The error:
NullReferenceException: Object reference not set to an instance of an object
The Script:
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class CreateNewCharacter : MonoBehaviour {
private BasePlayer newPlayer;
private bool isMageClass;
private bool isWarriorClass;
private bool isRogueClass;
private bool isClercClass;
private bool isRangerClass;
private bool isDruidClass;
private string playerName;
// Use this for initialization
void Start () {
newPlayer = new BasePlayer();
}
// Update is called once per frame
void Update () {
}
void OnGUI()
{
// creates a name and limits it to 15 letters
playerName = GUILayout.TextArea(playerName, 15);
// choose your class
isMageClass = GUILayout.Toggle(isMageClass, "Mage Class");
isWarriorClass = GUILayout.Toggle(isWarriorClass, "Warrior Class");
isRogueClass = GUILayout.Toggle(isRogueClass, "Rogue Class");
isClercClass = GUILayout.Toggle(isClercClass, "Cleric Class");
isRangerClass = GUILayout.Toggle(isRangerClass, "Ranger Class");
isDruidClass = GUILayout.Toggle(isDruidClass, "Druid Class");
if (GUILayout.Button("Create"))
{
if (isMageClass) { newPlayer.PlayerClass = new BaseMageClass(); }
else if (isWarriorClass) { newPlayer.PlayerClass = new BaseWarriorClass(); }
else if (isRogueClass) { newPlayer.PlayerClass = new BaseRogueClass(); }
else if (isClercClass) { newPlayer.PlayerClass = new BaseClericClass(); }
else if (isRangerClass) { newPlayer.PlayerClass = new BaseRangerClass(); }
else if (isDruidClass) { newPlayer.PlayerClass = new BaseDruidClass(); }
// start player at level 1 and get the values set for them
newPlayer.PlayerLevel = 1;
newPlayer.Stregnth = newPlayer.PlayerClass.Stregnth;
newPlayer.Intelegence = newPlayer.PlayerClass.Intelegence;
newPlayer.Constitution = newPlayer.PlayerClass.Constitution;
newPlayer.Dexterity = newPlayer.PlayerClass.Dexterity;
newPlayer.Charisma = newPlayer.PlayerClass.Charisma;
newPlayer.Wisdom = newPlayer.PlayerClass.Wisdom;
// get player name and additional information
newPlayer.PlayerName = playerName;
StoreNewPlayerInfo();
SaveInformation.SaveAllInformation();
}
if (GUILayout.Button("Load")) { SceneManager.LoadScene("test"); }
}
// store all information on empty GameInformation Object
private void StoreNewPlayerInfo()
{
GameInformation.PlayerName = newPlayer.PlayerName;
GameInformation.PlayerLevel = newPlayer.PlayerLevel;
GameInformation.Stregnth = newPlayer.Stregnth;
GameInformation.Intelegence = newPlayer.Intelegence;
GameInformation.Constitution = newPlayer.Constitution;
GameInformation.Dexterity = newPlayer.Dexterity;
GameInformation.Charisma = newPlayer.Charisma;
GameInformation.Wisdom = newPlayer.Wisdom;
}
}
I also think the guy in the tutorial is using version 4.5 and I am using version 5.3
thanks in advance.