MiniMap Camera goes dark when sun goes "down"

Ok, first the disclaimer. I am NEW to Unity development. I am a web developer and have worked with C# and JS code for years.

Background of issue: I have a camera Game Object that I am using for a MiniMap. I also have a day night cycle that rotates a directional light to create a sun. When that directional light rotates and the sun goes down the MiniMap camera goes dark. Which makes total sense since there is no light to see things.

The question: How can I keep light for the MiniMap camera without effecting the view of the player camera? I need the player to see darkness when the sun goes down but the MiniMap needs to have the light level remain constant.

Thanks

Use a separate light for the minimap.

You can use layers to choose where a light is taking effect.

Mirrored here: Have cameras render using different light sources

The hacky way to do this is to use the OnPreRender and OnPostRender methods in a script that is attached to the cameras. In these methods, you have to activate and deactivate all the lights that the camera should render/not render.

Note that this is not recommended as it will probably have a severe impact on your FPS.

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

public class ExcludeLight : MonoBehaviour {

	public List<Light> Lights;
	public bool cullLights = true;

	
	void OnPreCull(){
		if(cullLights == true) {
			foreach (Light light in Lights){
				light.enabled = false;
			}
		}
	}
	
	void OnPostRender(){
		if(cullLights == true) {
			foreach (Light light in Lights){
				light.enabled = true;
			}
		}
	}
	
}

If the issue is a minimap being rendered as it is affected by scene light (you probably want it to be unlit, with no shadows), then it’s a lot more complicated. You have to use RenderToTexture to render the minimap camera’s scene, apply a Replacement Shader which makes the camera use a shader that renders everything unlit, and display the rendertexture somehow (via OnGUI or UI.Image).

Here are my scripts

This is the one that goes onto the map camera. Drag the Unlit shader into the unlitShader slot in the inspector, or un-comment the commented line.

using UnityEngine;
using System.Collections;

public class MapCamera : MonoBehaviour {

	public Shader unlitShader;

	void Start() {
    //unlitShader = Shader.Find("Unlit/Texture");
		GetComponent<Camera>().SetReplacementShader(unlitShader,"");
	}
}

This script can go to any GameObject I guess, I had it on my player object.
the material variable can hold a masked material, where the mask makes the minimap texture round, for example.
Leave the renderTexture variable alone, it gets assigned automatically.
the variable mapTextureSzite obviously controls the size of your minimap in pixels.

using UnityEngine;
using System.Collections;

public class MiniMap : MonoBehaviour {

	public RenderTexture renderTexture;
	public Material material;

	public FilterMode filterMode = FilterMode.Point;

	public Camera miniMapCamera;
        public Vector2 mapTextureSize = new Vector2(256,256);

	void Start() {

		renderTexture = new RenderTexture(mapTextureSize.x,mapTextureSize.y,16);
		miniMapCamera.targetTexture = renderTexture;
		
		renderTexture.filterMode = filterMode;

         }


	void OnGUI() {

		GUI.depth = 4;

		if(miniMapCamera.enabled == true) {

			if(Event.current.type == EventType.Repaint) {
				Graphics.DrawTexture(new Rect(Screen.width - mapTextureSize.x, Screen.height - mapTextureSize.y, mapTextureSize.x, mapTextureSize.y), renderTexture, material);
			}
		}


	}

}