- Home /
Fade to white after being killed - iPhone game
I'm using the following bit of code from the FPS script tutorial fade to white after death.
LevelLoadFade.FadeAndLoadLevel(Application.loadedLevel, Color.white, 2.0);
However I get an error message in the console:
Assets/myGame/Scripts/health.js(35,9): BCE0005: Unknown identifier: 'LevelLoadFade'.
Does LevelLoadFade not work for Unity iPhone? Can someone confirm this?
And if it doesn't can someone tell me what I need for Unity iPhone to get the Fade to white effect.
Thanks,
Answer by · Aug 23, 2010 at 01:54 AM
That error would indicate to me that the method hasn't been declared. LevelLoadFade isn't a native function in Unity - it's probably part of the FPS Tutorial.
I took the LevelLoadFade script from the FPS tutorial and added it to my assets then used that bit of code in another script. But comes up with even more similar errors.
Can someone confirm if this is not used for Unity iPhone?
Take a look at http://answers.unity3d.com/questions/1375/errors-in-fps-tutorial - are they the same errors? The answer indicates that it may not work on iPhone at all.
thanks for the link and your help. Does anyone know a workaround to get it to work on Unity iPhone?
Answer by jtbentley · Aug 29, 2010 at 02:18 AM
Here's a script from one of the wiki's... I trigger it to fade a loading screen in, I wait for that to finish, then I trigger the Application.LoadLevel (which has the same image on the other side but fades out).
// FadeInOut // //-------------------------------------------------------------------- // Public parameters //--------------------------------------------------------------------
public var fadeOutTexture : Texture2D; public var fadeSpeed = 0.3;
var drawDepth = -1000;
//-------------------------------------------------------------------- // Private variables //--------------------------------------------------------------------
private var alpha = 1.0;
private var fadeDir = -1;
//-------------------------------------------------------------------- // Runtime functions //--------------------------------------------------------------------
//--------------------------------------------------------------------
function OnGUI(){
alpha += fadeDir * fadeSpeed * Time.deltaTime;
alpha = Mathf.Clamp01(alpha);
GUI.color.a = alpha;
GUI.depth = drawDepth;
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), fadeOutTexture);
if (alpha<0.01) {
Destroy(gameObject,0);
}
}
//--------------------------------------------------------------------
function fadeIn(){ fadeDir = -1;
}
//--------------------------------------------------------------------
function fadeOut(){ fadeDir = 1;
}
function Start(){ alpha=1; fadeIn();
}
JT, Thanks it works very well. However there is one slight issue.
In the console I get the following message:
"There are no audio listeners in the scene. Please ensure there is always one audio listener in the scene"
There is an audio listener in the scene and it is checked in the inspector, in fact it is on the same $$anonymous$$ain Camera I attached the script to.
Does some other script deactivate the camera or the AudioListener component? If at any point either of those are disabled, even for a single frame, that error will show up.
~ExplodingCookie