static Material Create( string materialName, string shader )

book_4_sparkGenerated
code_blocksInput

Description

The Create method is a static method of the Material class in the Sandbox namespace. It is used to create a new instance of a Material using a specified material name and shader. This method is useful for generating materials dynamically at runtime with specific shader configurations.

Usage

To use the Create method, call it statically from the Material class, providing the required parameters:

  • materialName (string): The name of the material to be created. This is typically used to identify the material within the application.
  • shader (string): The name of the shader to be used with this material. The shader defines how the material will be rendered.

The method returns a new Material object configured with the specified shader.

Example

// Example of creating a new material with a specific shader
string materialName = "MyCustomMaterial";
string shaderName = "StandardShader";

Material newMaterial = Material.Create(materialName, shaderName);

// Use the new material in your scene or game object
GameObject myObject = new GameObject();
myObject.AddComponent<Renderer>().Material = newMaterial;