- Home /
Using Color.Lerp with Lightweight Render Pipeline
Good day,
Would be great to receive help on using Color.Lerp with the Lightweight Render Pipeline. Using it with the Standard Shader seems to work fine but unfortunately not the same with the Lightweight Render Pipeline Lit Shader. I am trying to create a material for a number of objects in such a way that the objects in front differ in colour from the one's at the back and in between there is some kind of blend in the colours.
Renderer obstacleRenderer = newObstacle.GetComponent<Renderer>();
Material obstacleMaterial = new Material(obstacleRenderer.sharedMaterial);
float colourPercent = randomCoord.y / (float)currentMap.mapSize.y;
obstacleMaterial.color = Color.Lerp(currentMap.forgroundColour, currentMap.backgroundColour, colourPercent);
obstacleRenderer.sharedMaterial = obstacleMaterial;
The randomCoord variable is in reference to a method for picking a random tile of quads in the scene to put the obstacles.
newObstacle variable is a transform used for instantiating obstacles.
currentMap.foregroundColour and currentMap.backgroundColour are public colour variables for changing the colour in the inspector of the editor.
Any help would be really useful. Thank you
Answer by bwaite87 · Jun 21, 2019 at 03:18 AM
Instead of using
obstacleMaterial.color = Color.Lerp(currentMap.forgroundColour, currentMap.backgroundColour, colourPercent);
try using this instead:
obstacleMaterial.SetColor("_BaseColor", Color.Lerp(currentMap.forgroundColour, currentMap.backgroundColour, colourPercent);
Your answer
Follow this Question
Related Questions
URP material set texture scale 0 Answers
How does Material's "SetShaderPassEnabled" work? 1 Answer
How to set pre-render properties to UGUI Image? 0 Answers
Best way to swap between view modes 0 Answers