how do i have two different modes?,How do you have two different modes?

In the game that i am currently working on i have ran into a issue i want to have a building and a playing mode. in the building mode i want the camera to pan out and be able to place and remove things around the map similar to clash of clans. In the play mode i want the player to be able to walk around their village. how would i be able to have the player switch between these two modes?,In the game that i am planning i have ran into a issue. What i want to do is have a way for players to have a build mode where they can place building then a playing mode where they can walk around the map how would i do this?

Assuming that you have the building-mechanic and player-move-stuff figured out and only looking for a way to switch modes, there are a few ways to do it. Since this would be (I guess) a core mechanic in your game where you want to be able to change stuff with ease (like changing the UI to get a build-menu / go for build-music etc.) I’d probably do something like this:


Create a static class with the only purpose of keeping track of the gamemode, and also tell the objects that care when the mode is change and/or what it’s changed to. Note that this is a static class and not a MonoBehaviour. We’ll also create an enum to be used for this purpose. Lastly, we want a script to manually switch between these modes. Could be a MonoBehaviour handling input.

ENUM

public enum GameMode {
     Play,
     Build
}

STATIC CLASS

public static class GameModeManager {
    // The public static event is what we are going to subscribe to from our  
    // other scripts. This event is Invoked when something changes the CurrentMode
    // property, wherever from.  

    public static event Action onGameModeChanged;
    private static GameMode currentMode;
    public static GameMode CurrentMode {
        get => currentMode;
        set {
            currentMode = value;
            onGameModeChanged?.Invoke();
        }
    }
}

INPUT MONOBEHAVIOUR

public class InputGameModeSwitcher : MonoBehaviour {
    private void Update() {
        if(Input.GetKeyDown(KeyCode.B)) {
             GameModeManager.CurrentMode = GameMode.Build;
        }
        if(Input.GetKeyDown(KeyCode.P)) {
             GameModeManager.CurrentMode = GameMode.Play;
        }
    }
}

This is enough for a very basic core. What you need to do next is having stuff react to the change of mode. This way, you can implement behaviour for every object where this is needed, without having to touch this core class. What you need to do is registering to the event the static class throws. Like, as an example, the camera could do something like this:

public class CameraMovement : MonoBehaviour {
     // Register this script to listen to changes in the game mode.
     // Run the "ChangeCamera" method when this happens.
     // Don't forget to unregister from events in the case the object is disabled.

    private void OnEnable() => GameModeManager.onGameModeChanged += ChangeCamera;
    private void OnDisable() => GameModeManager.onGameModeChanged -= ChangeCamera;

    private void ChangeCamera() {
        switch (GameModeManager.CurrentMode) {
            case GameMode.Build:
                //Set build camera
                break;
            case GameMode.Play:
                //Attach camera to player and initialise position
                break;
        }
    }
}

Using this method, it’s easy to do the same thing with other parts of the game, like if the player-movement controller should be disabled in build-mode:

public class PlayerMovement : MonoBehaviour {

    private void OnEnable() => GameModeManager.onGameModeChanged += ToggleControl;
    private void OnDisable() => GameModeManager.onGameModeChanged -= ToggleControl;

    private void ToggleControl() {
        switch (GameModeManager.CurrentMode) {
            case GameMode.Build:
                //Disable movement 
                break;
            case GameMode.Play:
                //Enable movement
                break;
        }
    }
}

Or if you want like a menu to be displayed:

public class BuildMenu : MonoBehaviour {

    private void OnEnable() => GameModeManager.onGameModeChanged += ToggleMenu;
    private void OnDisable() => GameModeManager.onGameModeChanged -= ToggleMenu;

    private void ToggleMenu() {
        switch (GameModeManager.CurrentMode) {
            case GameMode.Build:
                //Show menu
                break;
            case GameMode.Play:
                //Hide menu
                break;
        }
    }
}

And so on. Hopes this helps! :slight_smile:

A set of numbers can have more than one mode (this is known as bimodal if there are two modes) if there are multiple numbers that occur with equal frequency, and more times than the others in the set.
PaybyPlateMa Pay Online