Void Update not detecting Input

Hello all

I have started a coding to enable or disable a camera when the M key is pressed, But I have run into a issue, when the M key is pressed nothing happens, I have looked in the inspector and the “mode” value isn’t changing.

code as follows:

using UnityEngine;
using System.Collections;

public class MainMap : MonoBehaviour {

	public int mode = 1;
	public GameObject MapCam;


	
	// Update is called once per frame
	void Update () {
		if(Input.GetKeyDown(KeyCode.M)) {
			if (mode == 1) {
				mode = mode - 1;
				MapCam.SetActive (true);

			}
			if (mode == 0) {
				mode = mode + 1;
				MapCam.SetActive (false);


			}
		}

	}



}

You need else if not anther if statement. Current your code goes

mode = 1

M pressed = yes

is mode 1? Yes. Make mode 0

is mode 0? Yes. Make mode 1

So it never changes

EDIT

Although if you only have 2 states, I’d do something like this:

 using UnityEngine;
 using System.Collections;
 
 public class MainMap : MonoBehaviour {
 
     public bool mode = true;
     public GameObject MapCam;
     private float keyDelay = 0.3f;
     private float nextKey = 0f;
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKeyDown(KeyCode.M) && Time.time > nextKey) {
             mode = !mode;
             nextKey = Time.time + keyDelay;
             if(mode)
                 MapCam.SetActive(true);
             else
                 MapCam.SetActive(false);
             }
         
         }
     }
 }

But the choice is yours of course.