Quantcast
Channel: Questions in topic: "playerprefs"
Viewing all articles
Browse latest Browse all 1333

My MainCharacter is not being instantiated when awake?

$
0
0
@Bunny83 @hexagonius I am a beginner in unity i am learning using recreating a project .When I run project I get an error "Object reference not set to an instance of an object GameManager.Awake () (at Assets/Scripts/GameManager.cs:97)". My MainCharater(project has multiple Characters) is not loading on awake not even in scene/inspector. Here is Awake() function script public class GameManager : MonoBehaviour { private void Awake() { if (Instance == null) { Instance = this; } else { UnityEngine.Object.DestroyImmediate(Instance.gameObject); Instance = this; } CreateNewCharacter(CharacterManager.Instance.CurrentCharacterIndex); } I am facing issues in CreateNewCharacter from CurrentcharacterIndex. public class CharacterManager : MonoBehaviour { public static readonly string CURRENT_CHARACTER_KEY = "MY_CURRENT_CHARACTER"; public GameObject[] characters; public static CharacterManager Instance { get; private set; } public int CurrentCharacterIndex { get { return PlayerPrefs.GetInt(CURRENT_CHARACTER_KEY, 0); } set { PlayerPrefs.SetInt(CURRENT_CHARACTER_KEY, value); PlayerPrefs.Save(); } } I am not getting it does this have to do with json or something else please help me by elaborating with pics Thankyou..

Viewing all articles
Browse latest Browse all 1333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>