Use
.env
files in your Unity projects.
https://docs.unity3d.com/Packages/[email protected]/manual/index.html
{
"dependencies": {
"xyz.candycoded.env": "https://github.com/CandyCoded/env.git#v1.1.0",
...
}
}
{
"dependencies": {
"xyz.candycoded.env": "1.1.0",
...
},
"scopedRegistries": [
{
"name": "candycoded",
"url": "https://registry.npmjs.com",
"scopes": ["xyz.candycoded"]
}
]
}
Create a .env
file at the root of your project, outside of the Assets/
folder, and paste the following content:
DEBUG=true
Or use the Editor planel found by navigating to Window > CandyCoded > Environment File Editor.
Note: Don't forget to add
.env
to your.gitignore
file before committing any changes!
Now you can reference the variables and their values with the key specified in the .env
file. Supported value types
are string
, bool
, double
, float
, and int
.
if (env.TryParseEnvironmentVariable("DEBUG", out bool isDebug))
{
Debug.Log($"Debug Mode is: {(isDebug ? "ON" : "OFF")}");
}