Unity3d sharedMaterial.SetColor
时间: 2024-05-03 20:21:52 浏览: 105
The sharedMaterial.SetColor method is used to set the color of a material in Unity3D.
Syntax:
public void SetColor(string propertyName, Color color);
Parameters:
- propertyName: The name of the property to set the color for (e.g. "_Color" for the main color of a material).
- color: The color to set the property to.
Example:
To set the color of a material to red, you can use the following code:
```csharp
using UnityEngine;
public class MaterialColorExample : MonoBehaviour
{
public Material material;
void Start()
{
material.sharedMaterial.SetColor("_Color", Color.red);
}
}
```
In this example, we have a material assigned to the "material" variable, and we use the SetColor method to set the "_Color" property of the material to red. The sharedMaterial property is used to ensure that the change is applied to all instances of the material.
阅读全文