Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetGlobalFloat

Sets a global float property for all shaders.
Read time 2 minutesLast updated 11 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.CoreModule

SetGlobalFloat(string, float)

Sets a global float property for all shaders.
public static void SetGlobalFloat(string name, float value)

Parameters

name

The name of the property.

value

Remarks

Global properties are used if a shader needs them but the material does not have them defined (for example, if the shader does not expose them in Properties block).
Usually this is used if you have a set of custom shaders that all use the same "global" float (for example, density of some custom fog type). Then you can set the global property from script and don't have to setup the same float in all materials.
The following example sets the global float property
_MyFloat
to
1
in all shaders.

Examples

using UnityEngine;public class SetGlobalFloatExample : MonoBehaviour{ void Start() { Shader.SetGlobalFloat("_MyFloat", 1.0f); }}

SetGlobalFloat(int, float)

Sets a global float property for all shaders.
public static void SetGlobalFloat(int nameID, float value)

Parameters

nameID

The name ID of the property retrieved by Shader.PropertyToID.

value

Remarks

Global properties are used if a shader needs them but the material does not have them defined (for example, if the shader does not expose them in Properties block).
Usually this is used if you have a set of custom shaders that all use the same "global" float (for example, density of some custom fog type). Then you can set the global property from script and don't have to setup the same float in all materials.
The following example sets the global float property
_MyFloat
to
1
in all shaders.

Examples

using UnityEngine;public class SetGlobalFloatExample : MonoBehaviour{ void Start() { Shader.SetGlobalFloat("_MyFloat", 1.0f); }}