- Home /
Make changes to Sprites/Default Material and not saving this change in prefabs.
I have a background which has a sprite renderer with Sprites /Default Material on it , and i change the materials color in the update function and after the game ends and i press playagain the material already has that color applied to it , i want that color to be reset back to the one which as at the start.
[EDIT]:
@saud_ahmed020 Here is the little code snippet .
I have simple Material and i changed it's color in default . like
Background.GetComponent ().material.color = Color.Lerp (new Color (0.20f, 0.19f, 0.19f, 1), new Color (0.78f, 0.11f, 0.11f, 1), time / 4);
and i also have game setup function which i call in the start and at replay . that function contains the following code .
Background.GetComponent ().material.color = Color.black;
But the the color doesn't change back to normal after the first play , i mean the line doesn't work when i press replay , i have debugged the code , the code at this breakpoint is reachable but is not having any affect , really confused.
@saud_ahmed020 I have shared the code in the question edit.
@sourav13 I have tested it. It works but I think you are doing something different that you are saying.
using UnityEngine;
using System.Collections;
public class Test : $$anonymous$$onoBehaviour
{
void Start(){
GetComponent<SpriteRenderer>().material.color = Color.Lerp (new Color (0.20f, 0.19f, 0.19f, 1),
new Color (0.78f, 0.11f, 0.11f, 1), 1);
Invoke("ChangeColor",1);
}
void ChangeColor()
{
GetComponent<SpriteRenderer>().material.color = Color.black;
}
}
You have done quite the reverse of $$anonymous$$e want the Color to be black at the start and than you have tried invoke (here i'm Lerping in update , that's ok ) and than i have condition in update which stops the script and another function in which i'm resetting the color and turning back the script on . ( this function runs on a button click ) .
Answer by tanoshimi · Jun 07, 2016 at 06:27 AM
At a guess, you're modifying sharedMaterial.color, which will modify the asset on disk and persist even after playmode stops. To modify just the instance of the material attached to the object during runtime, change material.color instead.
@tonoshimi I have updated the question with little code , I'm using material.color not shared$$anonymous$$aterial.color.
Your answer