- Home /
Projector.material = sharedMaterial ?
I'm playing with projectors, and to change the texture and color by script, the only way I found is use projector.material :
projector.material.SetTexture ("_Texture", myTexture);
projector.material.SetColor ("_Color", myColor);
Unfortunately, it changes all the projectors of my scene using the material like I was using the propertie "sharedMaterial" of a renderer.
Is there any other way to solve that than using one material per projector ?
Answer by Kev1@Ubi · Nov 23, 2012 at 08:19 AM
Well I made my own system. A Start :
Material newMaterial = new Material(projector.material);
projector.material = newMaterial ;
It's probably not really efficient but it works :)
Answer by oLDo · Oct 03, 2017 at 07:30 AM
I have created extension for this change.
/// <summary>
/// Projector material is like renderer.shaderMaterial. if you need to change instance, use this extension.
/// </summary>
/// <param name="projector"></param>
/// <param name="color"></param>
/// <param name="keepAlpha"></param>
public static void ChangeColor(this Projector projector, Color color, bool keepAlpha = true)
{
var mat = new Material(projector.material);
if (!mat.name.Contains("(Instance)"))
mat.name += " (Instance)";
if (keepAlpha)
color.a = mat.color.a;
mat.color = color;
projector.material = mat;
}
Your answer
Follow this Question
Related Questions
Accessing a projectors renderer 2 Answers
Project a solid color onto a game object 1 Answer
How to check if two objects share the same material within an if statement? 0 Answers
Keep replaced materials of a Game Object even after ending the Play Mode C# 0 Answers
Projector - blob shadow. How to change the material's alpha channel C# 2 Answers