Created
November 11, 2021 07:53
-
-
Save GT3000/baae0a8a9988a43dcf3096f9827b9c8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerStats | |
{ | |
public int userLevel; | |
public string userName; | |
public int manaLevel; | |
public static int goldTotal; | |
//Just a regular constructor that initializes non-static members | |
public PlayerStats() | |
{ | |
Debug.Log("PlayerStats instance members initialized. These are the non-unique instances"); | |
} | |
//Initializes static members first before all the non-static instanced members even though they went first | |
static PlayerStats() | |
{ | |
goldTotal = 1000; | |
Debug.Log("Static members iniitalized here. These are the unique static members that hold data."); | |
} | |
} | |
//Attached to gameobject and actually drives the code above to execute | |
public class PlayerCharacter: MonoBehaviour | |
{ | |
private void Start() | |
{ | |
PlayerStats p1 = new PlayerStats(); | |
PlayerStats p2 = new PlayerStats(); | |
PlayerStats p3 = new PlayerStats(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment