'Having troubles with unity camera depth texture
I am trying to implement a shader that makes things darker the further from the camera they are,the way it works underwater, but when I try to work with the camera depth ,I get "error CS0103: The name 'depthTextureMode' does not exist in the current context".
This is the code I tried to run
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode,ImageEffectAllowedInSceneView]
public class FogEffect : MonoBehaviour
{ public Material _mat;
void Start()
{
GetComponent<Camera>().depthTextureMode = depthTextureMode.Depth;
}
void Update()
{
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
Graphics.Blit(source,destination,_mat);
}
}
Solution 1:[1]
DepthTextureMode is an enum and the first letter needs to be uppercase.
This compiled and run without issues on my machine.
using UnityEngine;
public class FogEffect : MonoBehaviour
{
void Start()
{
GetComponent<Camera>().depthTextureMode = DepthTextureMode.Depth;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | JeanLuc |
