// Get the renderer component of the game object Renderer renderer = gameObject.GetComponent(); // Get the current material Material currentMaterial = renderer.material; // Set a new color for the material currentMaterial.color = Color.red;
// Get the renderer component of the game object Renderer renderer = gameObject.GetComponentThe package library for UnityEngine Material is part of the Unity engine's core packages and doesn't require any additional external packages to be installed.(); // Get the current material Material currentMaterial = renderer.material; // Load a texture from the Resources folder Texture2D texture = Resources.Load ("Textures/myTexture"); // Set the texture to the material's main texture slot currentMaterial.mainTexture = texture;
The material class.