You've successfully subscribed to Hacking with Unity - Learn how to create your own games
Great! Next, complete checkout for full access to Hacking with Unity - Learn how to create your own games
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.

Set up global variable in Unity

Ben Liu
Ben Liu

Keep your global variables separately is always a good practice no matter what programming language you are working with.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AppConstants : MonoBehaviour {
	public static int ENEMY1_SCORE = 10;
}

To use them:

Debug.Log(AppConstants.ENEMY1_SCORE);

Ben Liu

Please feel free to contact me if you have any question. <br> https://t.me/NeedoneApp