Skip to content

Instantly share code, notes, and snippets.

@rob5300
Created April 28, 2019 11:32
Show Gist options
  • Save rob5300/6dac1b315dad0db0bc1418bcb983bac9 to your computer and use it in GitHub Desktop.
Save rob5300/6dac1b315dad0db0bc1418bcb983bac9 to your computer and use it in GitHub Desktop.
Example of accessing static members
//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