- Home /
How to create a fade out respawn from falling?
I am working on an indie game and me and my team are in pre production. I am starting to put together a test build for testing the game mechanics. I have a question regarding programming: How to create a fade out respawn from falling?
-Fade out: When the player falls into the zone where they are forced to get damaged, I want the screen to fade out slowly and fade back in really fast when the player respawns.
-Respawn: I want to set spawn points and make the game determine where the player respawns by choosing the closest respawn point.
-Damage: Before the player respawns, I want the player to take actual damage while falling. So the player doesn't die when they fall, but just receive a small portion of damage.
Why is this question downvoted/flagged? I don't see anything obviously wrong with it - it's not a duplicate (that I know of), the question is fairly clear, the grammar is good...
Fade out http://answers.unity3d.com/questions/12831/fade-in-from-black, Respawn http://answers.unity3d.com/questions/15078/trigger-respawn-after-collision, Falling Damage http://answers.unity3d.com/questions/6545/fall-damage-issue, plus the fact that there are multiple parts to the same question.
Answer by BoredKoi · Jun 11, 2010 at 04:26 PM
Well, there's all manners of ways to do the fading. Below is an example of a script placed on a GO representing your light, and how to fade out it with some time-stepping. Fading in would require reversing the manipulation on lightIntensity. I realize that the fading in this example is packed in the update; in your case you could fire it off in a Coroutine. In fact, if you are applying damage, you could do that in concert with the fade out/back in action. As for respawning, ideally you'd have that collection of spawn Vector3[] points init'd and cached before game starts, as well as the transform of your player. That way you can simply iterate over that built in array, calling the static Vector3.Distance function and select the closest one to the player as the new spawn position.
using UnityEngine; using System.Collections;
public class LightFader : MonoBehaviour {
public Light thisLight;
float alphaFadeValue = 0.0f;
// Use this for initialization
void Start () {
thisLight = light;
}
// Update is called once per frame
void Update () {
if(alphaFadeValue < .4)
{
alphaFadeValue += Mathf.Clamp01(Time.deltaTime / 10);
thisLight.intensity = alphaFadeValue;
}
}
}
Your answer
Follow this Question
Related Questions
Respawned with Camera problem 2 Answers
Fade on death! 1 Answer
Player taking damage on collision. Can't get the script to work!? 1 Answer
Need help with enemy respawn script 1 Answer