目录索引
译文
数字(number)与滑条(slider)两种类型的属性允许我们在着色器中添加数值类型的变量。假设我们打算创建一个实现光照功能的着色器,“0”代表亮度为 0%,“1”代表亮度为 100% ,那么我们就可以创建一个范围为0到1的滑条类型属性来表示亮度。
声明数字与滑条类型的语法如下所示:
// name ("display name", Range(min, max)) = defaultValue
// name ("display name", Float) = defaultValue
// name ("display name", Int) = defaultValue
Shader "InspectorPath/shaderName"
{
Properties
{
_Specular ("Specular", Range(0.0, 1.1)) = 0.3
_Factor ("Color Factor", Float) = 0.3
_Cid ("Color id", Int) = 2
}
}
在上面的例子中,我们声明了三个属性,分别是名为“_Specular”的范围类型属性、名为“_Factor”的浮点数类型属性与名为“_Cid”的整型类型属性。
原文对照
These types of properties allow us to add numerical values to our shader. Let’s suppose that we want to create a shader with functions of illumination, where “zero” equals 0% illumination and “one” equals 100% illumination. We can create a range for this (e.g. Range (min, max)) and configure the minimum, maximum and default illumination values.
The following syntax declares numbers and sliders in our shader:
// name ("display name", Range(min, max)) = defaultValue
// name ("display name", Float) = defaultValue
// name ("display name", Int) = defaultValue
Shader "InspectorPath/shaderName"
{
Properties
{
_Specular ("Specular", Range(0.0, 1.1)) = 0.3
_Factor ("Color Factor", Float) = 0.3
_Cid ("Color id", Int) = 2
}
}
In the previous example we declared three properties, a “floating range” type called _Specular, another “floating scale” type called _Factor, and finally, an “integer” type called _Cid.

![[udemy]在 Unity 中创建 RPG 游戏的终极指南-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/04/TheUltimateGuidetoCreatinganRPGGameinUnity.webp)
![[udemy]学习在 Unity 和 C# 中创建吸血鬼幸存者风格的游戏-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/04/LearnToCreateAVampireSurvivorsStyleGameinUnityC.webp)
![[udemy] 在 Godot 4 中创建完整的 2D 幸存者风格游戏-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/CreateaComplete2DSurvivorsStyleGameinGodot4.webp)
![[gamedev tv] RPG核心战斗力的创造者 :学习中级 Unity C# 编码-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/04/RPGCoreCombatCreatorLearnIntermediateUnityCCoding.png)
![[gamedev tv]Unity 2.5D 回合制角色扮演游戏-软件开发学习笔记](https://gamedevfan.cn/wp-content/uploads/2025/05/Unity2.5DTurn-BasedRPG.webp)




暂无评论内容