Question by
redgroupclan · Apr 04, 2016 at 08:33 PM ·
scripting problemfadein
How do I get the screen to fade in when a trigger is triggered?
When the player walks into the trigger TeleportToL2, I need the screen to turn black and then fade in. The script on the trigger so far:
#pragma strict
var TeleportToL2Dest: Transform; // drag the destination empty here
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player")
{
// move and align the player to the destination empty GO
other.transform.position = TeleportToL2Dest.position;
other.transform.rotation = TeleportToL2Dest.rotation;
}
}
I found a script off of Google, but it only fades as soon as the scene starts:
#pragma strict
// FadeInOut
var fadeTexture : Texture2D;
var fadeSpeed = 0.2;
var drawDepth = -1000;
private var alpha = 1.0;
private var fadeDir = -1;
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), fadeTexture);
}
What would the code be to apply this script to only work when the TeleportToL2 trigger is triggered?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612074159im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to fade in and out two logos inside the same scene? [c#] 1 Answer
Audio Fade With Toggle 1 Answer
How to fade in and out two panels in a scene? (c#) 1 Answer
FadeInOut problem 0 Answers