Emission Script

I’m having a bit of trouble
I have two simple scripts.

One, is if I press the space key, the emission turns off and will turn on again if I let go of the space bar

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

public class FlitsUit : MonoBehaviour
{
    // 
    public Material material;

    private void Update()
    {
        if (UnityEngine.Input.GetKey(KeyCode.Space))
        {
            material.DisableKeyword("_EMISSION"); ;

        }
        else
        {

            material.EnableKeyword("_EMISSION");
        }
    }

}

The other one is, If I press E, the emission will turn on and If I press D it will turn off.

They both work, but If i combine them, which is needed for the behaviour I want, they “D” Key doesn’t work anymore. It will only turn off for a split second and come on again.

The code for the emission script is

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

public class KopLamp : MonoBehaviour
{
    public Material material;




    void Update()
    {

        if (Input.GetKeyDown(KeyCode.E))
        {
            material.EnableKeyword("_EMISSION");
        }

        if (Input.GetKeyDown(KeyCode.D))
        {

      
            material.DisableKeyword("_EMISSION");


        }
    }
}

Could someone help me with this?
Thanks!

The problem lies in the FlitsUit class. Look at the Update. If you hold down Spacebar, the following piece of code evaluates to true every frame:

	if (UnityEngine.Input.GetKey(KeyCode.Space))
	{
		material.DisableKeyword("_EMISSION"); ;

	}

But when you stop holding Spacebar down, the following piece of code evaluates to false and is executed every frame:

	else
	{

		material.EnableKeyword("_EMISSION");
	}

You can create some sort of communication between your scripts (I used bool “boo”), so they could better understand each other’s behaviour:

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

public class KopLamp : MonoBehaviour
{
	public Material material;
	public bool boo;
	
	void Update(){
		if (Input.GetKeyDown(KeyCode.E)){
			boo = false;
			//material.EnableKeyword("_EMISSION");
		}
		
		if (Input.GetKeyDown(KeyCode.D)){
			boo = true;
			//material.DisableKeyword("_EMISSION");
		}
	}
}

and the second script:

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

public class FlitsUit : MonoBehaviour
{
	public Material material;
	KopLamp kopLamp;
	
	void Awake(){
		kopLamp = FindObjectOfType<KopLamp>();
	}
	
	void Update(){
		if (Input.GetKey(KeyCode.Space)){
			material.DisableKeyword("_EMISSION");
		} else {
			if (kopLamp.boo){
				material.DisableKeyword("_EMISSION");
			} else {
				material.EnableKeyword("_EMISSION");
			}
		}
	}
}