Darkness system

Is there a way to check if mesh/object is covered by shadow or something like that? I would like to achieve effect that you can hide in shadows, or hide bodies. I would prefer to do it realtime - not by predefinied areas, because i would like to include flashlights etc.

Use light probes

Are you doing this in 2D or 3D? 2D is much easier to do this.

I use something similar in my AI, but its not exactly perfect yet.
I have a rendertexture which renders the player and a shadow layer from a camera placed on the AI. Every X seconds (I use 0.1) it starts a coroutine which gets the rendertexture and converts it to a texture and then convert that to a 2D array of colors. Then I have a thread which compares the grayscale value of every single pixel in said array to a predefined color set in the inspector. And then it uses some more advanced stuff to change how my AI reacts, but thats seems offtopic for this. The shadow layer is the entire map copy-pasted to a new layer and with all the mesh renderes turned to shadows only, so they wont render, just cast/receive shadows.

It works great and I have not noticed any performance drops, but its not perfect. Im not a lighting expert, so my scene is very poorly lit, just 1 directional light and a few point lights here and there. So when the player stands between the AI and the player, the AI doesn’t see the player because all the light hits the back of the player… I am in the process of trying to fix this, but you know…

It might not work perfectly for your scenario, but its atleast a reasonable dynamic shadow detection system.

//Made by Imre Angelo aka Lahzar on the unity forums
//You should be able to fill in the blanks/predefined variables
//Also remember to play around with ambient occlusion. Can make things better & easier! Enjoy!

static bool processing = false;

void Start()	{
		#region Create RenderTexture
		RenderTexture template = GetComponentInChildren<Camera>().targetTexture;
		rt = new RenderTexture(template.width, template.height, template.depth);
		rt.Create();
		GetComponentInChildren<Camera>().targetTexture = rt;
		#endregion
}

#region Shadow Detection
	IEnumerator RenderToTexture()	{
		processing = true;
		yield return new WaitForEndOfFrame();

		RenderTexture.active = rt;
		text = new Texture2D(rt.width, rt.height);
		text.ReadPixels(new Rect(0,0,rt.width,rt.height),0,0);
		text.Apply();
		pixels = text.GetPixels();
		DebugMaterial.mainTexture = text;

		yield return new WaitForSeconds(freq);

		Thread t = new Thread(ComparePixels);
		t.Start();
		t.Join();
		processing = false;
		yield return visible;
	}

	void ComparePixels()	{
		foreach(Color p in pixels)	{
			if(p.grayscale >= bright.grayscale)	{
				visible = true;
				break;
			} else {
				visible = false;
			}
		}
	}
	#endregion