Version: 2020.1
언어: 한국어

MaterialConstructor

매뉴얼로 전환
public Material (Shader shader);
public Material (Material source);

파라미터

shader Create a material with a given Shader.
source Create a material by copying all properties from another material.

설명

Create a temporary Material.

If you have a script which implements a custom special effect, you implement all the graphic setup using shaders & materials. Use this function to create a custom shader & material inside your script. After creating the material, use SetColor, SetTexture, SetFloat, SetVector, SetMatrix to populate the shader property values.

See Also: Materials, Shaders.

using UnityEngine;

public class Example : MonoBehaviour { // Creates a material from shader and texture references. Shader shader; Texture texture; Color color;

void Start() { Renderer rend = GetComponent<Renderer> ();

rend.material = new Material(shader); rend.material.mainTexture = texture; rend.material.color = color; } }
using UnityEngine;

public class Example : MonoBehaviour { // Creates a cube and assigns a material with a builtin Specular shader. void Start() { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); Renderer rend = cube.GetComponent<Renderer> (); rend.material = new Material(Shader.Find("Specular")); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961