Camera Culling Mask Change

Hi guys,

I am pretty new to Unity and have a question.
I have 2 scripts that are basically 2 flashlights.

First is a normal flashlight, and the second one is a UV light flashlight. (Same thing, but a different color to the light).

My problem is the following:
I have created a new layer called UVlight (Layer 10).

I want the camera (PlayerCamera) to render everything, besides the UVlight layer. When the player turns his UVFlashlight on, the objects tagged with UVlight layer to become visible if the player shines the light over them.

Here is the flashlight script:
using UnityEngine;
using System.Collections;

public class flashLight : MonoBehaviour {

	private Light fL;
	
	void Start()
	{
		fL = gameObject.GetComponent< Light >();
	}
	
	void Update()
	{
		if( Input.GetKeyDown( KeyCode.F ) )
		{
			if( fL != null) fL.enabled = !fL.enabled;      
		}
	}
}

UV Flashlight Script:

using UnityEngine;
using System.Collections;

public class flashLightUV : MonoBehaviour {

    private Light fLUV;
	
	void Start()
	{
        fLUV = gameObject.GetComponent< Light >();
	}
	
	void Update()
	{
        if (Input.GetKeyDown(KeyCode.U))
        {
            if (fLUV != null)
            {
                fLUV.enabled = !fLUV.enabled;
            }
        }
	}
}

Any ideas on how to do this?
I think it is a simple thing to do, but like I said, I’m kinda newbie at this and seek help from the more experienced devs.

Thanks in advance,
Vlad

Well a naive solution to this might be simply changing culling mask at runtime. For that you would just add something like this into your UV Flashlight script:

//decleration
[SerializeField] private LayerMask normalCMask;
[SerializeField] private LayerMask uvCMask;

//On UV light Turn on
...
Camera.main.cullingMask = uvCMask;
...

And you would setup culling masks in the inspector.
However more sofisticated solution would be to write your own shader, so the objects would be visible only if they are directly lit.
There i cannot assist, but here is a tutorial on how to write shaders:

You could have a camera set to render the UV layer, place it above your main camera so it renders everything. Disable/enable it with the flashlight script.

Ok, so I’m dumb.
I managed to make the Culling Mask change, but now I have a different problem.
For the objects set on the UV Layer, I want them to be visible only when the UVFlashlight shines over them. And for example if the light shines only on one part of the object, I only want that part to be visible, and not the entire object.

Is there any way i could do that?