Awake..DontDestroy and material.color.a

Hello,

I have a scene where I am fading in a texture.
using renderer. material.color.a
shader is transparent vertex lit.

it will fade in properly, but when I add a awake and don’t destroy on load
the texture will fade in ok as a stand alone scene but once that level gets called, it will fade in but also generate copies of the object like it’s been instantiated and the materials of the duplicated objects are missing,
Here’s the script.

//When I add this awake, it messes it up
/*function Awake()
{
	DontDestroyOnLoad(this);
}*/

var durationFade : float = 90.0;
var fade : float = 0.0;

function Start()
{
	renderer.material.color.a = fade;
}

function Update()
{
	if(ASManager.instance.levelLoaded == true)
	{
		FadeIn();
	}
}

function FadeIn()
{
	while(fade < 1.0)   
    { 
      fade += Time.deltaTime / durationFade;
      renderer.material.color.a = fade;
      yield; 
   	} 
   	 fade = 1;
   	 
}

If the scene is by itself it’s ok even with the awake function
but not when the level gets called and loaded.

I would like to use the object for the next levels that’s why I had the dont destroy.

Maybe I’m doing it wrong.

appreciate any help.

Thanks,
Ray

You may have solved this already, but if you want this to be present for other levels you should probably package this process into a prefab and put one of them in each of the levels you want the behavior.

I’d also recommend against using DontDestroyOnLoad for something like this-- because once you are done fading in this object will just soak up processor time doing nothing useful during an Update() call. It would probably be better to have a short-term object that handled this effect and then destroyed itself when it was done.

Or you could use a manager script with coroutines, like this. That way you can call a fade routine at any time and it stops running when done.

–Eric