How i can get variable from other script

My game has changeable difficulty in the main menu and I’m wondering how I can access it from other scripts to change things like enemy damage and something like that. I’ve been trying to find something about it and so far, I don’t quite understand how it works. Variable that i need access to is called mainMenuDifficulty.

You would want to make static variables.

public class OptionsMenu : Monobehavior
{
public static int difficulty;
//Example: 1=Easy, 2=Normal, 3=Hard, etc...
}

// On your other script, to access this variable
public class ChangeOptions : Monobehavior
{
// Inside a function or where ever you're changing the variable
OptionsMenu.difficulty = // Make your change here
}

Kind of a brief demonstration. Hope it was helpful :slight_smile:

2 Likes

ThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyouThankyou

1 Like

You are welcome, amigo :slight_smile: