Search Unity

Cannot Change Emission Value

Discussion in 'Editor & General Support' started by Mr_AgentFox, Aug 2, 2019.

  1. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    59
    Hey! Can anyone fix my issue? My emission value doesn't change, but all the tutorials I've watched tell you to write "material.Disable("_EMISSION");" and yes I have a variable for the material. I want my material emission to flicker when I am reloading. Any answers?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EmisionControl : MonoBehaviour
    6. {
    7.  
    8.     public Material emitValue;
    9.     public GunScript gunScript;
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         emitValue.EnableKeyword("_EMISSION");
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         if (gunScript.isReloading)
    20.         {
    21.             StartCoroutine(Flicker());
    22.         }
    23.     }
    24.  
    25.     IEnumerator Flicker()
    26.     {
    27.         emitValue.DisableKeyword("_EMISSION");
    28.         yield return new WaitForSeconds(1f);
    29.         emitValue.EnableKeyword("_EMISSION");
    30.         yield return new WaitForSeconds(.6f);
    31.         emitValue.DisableKeyword("_EMISSION");
    32.         yield return new WaitForSeconds(.4f);
    33.         emitValue.EnableKeyword("_EMISSION");
    34.         yield return new WaitForSeconds(.4f);
    35.         emitValue.DisableKeyword("_EMISSION");
    36.         yield return new WaitForSeconds(.6f);
    37.         emitValue.EnableKeyword("_EMISSION");
    38.     }
    39. }
    40.  
     
  2. Mr_AgentFox

    Mr_AgentFox

    Joined:
    Jun 23, 2019
    Posts:
    59
    Also, I get the console error "Object reference not set to an instance of an object"