Version: 2020.2
言語: 日本語
public void SetColor (string name, Color value);
public void SetColor (int nameID, Color value);

パラメーター

nameID プロパティー名 ID。Shader.PropertyToID を使って取得します。
name プロパティー名。例えば、"_Color"。
value 設定する Color 値。

説明

Sets a named color value.

多くのシェーダーでは複数の色を使用します。色を変更するには、SetColor を使用します (シェーダーの propertynName、または、プロパティー固有の nameID から識別)。

標準シェーダーを使用しているマテリアルの色の値を設定するとき、以前使用していないシェーダーの機能を有効にするために EnableKeyword を使用する必要があることに注意しなければなりません。詳細については Accessing Materials via Script を参照してください。

Common color names used by Unity's builtin shaders:
"_Color" is the main color of a material. This can also be accessed via color property.
"_EmissionColor" is the emissive color of a material.

See Also: color, GetColor, Shader.PropertyToID, Properties in Shader Programs.

//Attach this script to any GameObject in your scene to spawn a cube and change the material color
using UnityEngine;

public class Example : MonoBehaviour { void Start() { //Create a new cube primitive to set the color on GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

//Get the Renderer component from the new cube var cubeRenderer = cube.GetComponent<Renderer>();

//Call SetColor using the shader property name "_Color" and setting the color to red cubeRenderer.material.SetColor("_Color", Color.red); } }