Created
April 28, 2019 11:32
-
-
Save rob5300/6dac1b315dad0db0bc1418bcb983bac9 to your computer and use it in GitHub Desktop.
Example of accessing static members
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
//Game settings class | |
public class GameSettings | |
{ | |
//Declare this as static meaning it is accessable via the class name | |
public static RandomClass RandomSettings = new RandomClass(); | |
} | |
//Class decleration for Random. | |
public class RandomClass | |
{ | |
public float floatvar = 0867.9087f; | |
} | |
//Example of accessing the data from another class such as a Monobehaviour | |
//Have this in a new file called MyMono.cs | |
using UnityEngine; | |
public class MyMono : MonoBehaviour | |
{ | |
public void Start() | |
{ | |
Debug.Log("floatvar value: " + GameSettings.RandomSettings.floatvar); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment