Version: 2017.4
public Material (Shader shader);
public Material (Material source);

パラメーター

shader Shader からマテリアルを作成します
source別のマテリアルからすべてのプロパティーをコピーすることによってマテリアルを作成します

説明

一時的なマテリアルを作成します

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;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Shader shader; public Texture texture; public Color color; void Start() { Renderer rend = GetComponent<Renderer>(); rend.material = new Material(shader); rend.material.mainTexture = texture; rend.material.color = color; } }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Start() { GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); Renderer rend = cube.GetComponent<Renderer>(); rend.material = new Material(Shader.Find("Specular")); } }