Player is dead! And now?

When this happenas, I would like to:

  • change color os screen to blue
  • stop the controls of FPC
  • change position of FPC to the original coordinates
  • reset all the game (animations, GUIs, etc)

Any help?

Thanx

It is very difficuilt to give you exact ideas, because it depend a lot on your game structure, but here are some thoughts:

  • blue screen can be a gui texture that is set to screen.width and screen.height and have transparency
  • stop the controls by setting the player controller component active to false
  • change position by just sending a vector3 value to the players transform
  • The rest depends on the variables you use. You need to ask yourself which variables, arrays, animations etc needs to be reset for this. Normally the most of these would be your static (global) vars, but there might be some others 2

But once again, this very much depends on the way that you have planned and structured your game

Dying on ~1.27 minute:

Somewhere in your damage script!

function Die () {
	// Disable all script behaviours (Essentially deactivating player control)
	var coms : Component[] = GetComponentsInChildren(MonoBehaviour);
	for (var b in coms) {
		var p : MonoBehaviour = b as MonoBehaviour;
		if (p)
			p.enabled = false;
	}
    yield WaitForSeconds(2.0);
    LevelLoadFade.FadeAndLoadLevel(Application.loadedL  evel, Color.black, 2.0);
}
/*
	Usage:

	// Load my level	
	LevelLoadFade.FadeAndLoadLevel("mylevel", Color.white, 0.5);

	// Reset the current level
	LevelLoadFade.FadeAndLoadLevel(Application.loadedL  evel, Color.white, 0.5);
*/

static function FadeAndLoadLevel (level, fadeTexture : Texture2D, fadeLength : float)
{
	if (fadeTexture == null)
		FadeAndLoadLevel(level, Color.white, fadeLength);

	var fade = new GameObject ("Fade");
	fade.AddComponent(LevelLoadFade);
	fade.AddComponent(GUITexture);
	fade.transform.position = Vector3 (0.5, 0.5, 1000);
	fade.guiTexture.texture = fadeTexture;
	fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, false);
}

static function FadeAndLoadLevel (level, color : Color, fadeLength : float)
{
	var fadeTexture = new Texture2D (1, 1);
	fadeTexture.SetPixel(0, 0, color);
	fadeTexture.Apply();
	
	var fade = new GameObject ("Fade");
	fade.AddComponent(LevelLoadFade);
	fade.AddComponent(GUITexture);
	fade.transform.position = Vector3 (0.5, 0.5, 1000);
	fade.guiTexture.texture = fadeTexture;

	DontDestroyOnLoad(fadeTexture);
	fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, true);
}

function DoFade (level, fadeLength : float, destroyTexture : boolean)
{
	// Dont destroy the fade game object during level load
	DontDestroyOnLoad(gameObject);

	// Fadeout to start with
	guiTexture.color.a = 0;
	
	// Fade texture in
	var time = 0.0;
	while (time < fadeLength)
	{
		time += Time.deltaTime;
		guiTexture.color.a = Mathf.InverseLerp(0.0, fadeLength, time);
		yield;
	}
	guiTexture.color.a = 1;
	yield;

	// Complete the fade out (Load a level or reset player position)
	Application.LoadLevel(level);
	
	// Fade texture out
	time = 0.0;
	while (time < fadeLength)
	{
		time += Time.deltaTime;
		guiTexture.color.a = Mathf.InverseLerp(fadeLength, 0.0, time);
		yield;
	}
	guiTexture.color.a = 0;
	yield;

	Destroy (gameObject);

	// If we created the texture from code we used DontDestroyOnLoad,
	// which means we have to clean it up manually to avoid leaks
	if (destroyTexture)
		Destroy (guiTexture.texture);
}

Hi chubbspet. Thanks for the answer.

Can I animate this GUI (FADE IN) in the animation panel?

I don´t know how can I do it in the script

Any refence about it?

My game has a only level. Anyway to restart the game when the player dies without care with each details?

Hi badbii,

Nice game. Congrats.

But I don´t how to implement this in my game.

Tx.

  1. yes, I’m sure you should be able to create a texture with the alpha channel animated. Here is a better one though, call the camera component of your main camera and change the background property with code using GetComponent(“Camera”). You can create the illusion of animation by changing the color over time using Time.deltaTime*someVariable. The only thing with this is that it will be a pure color and not a texture like blood or whatever. But maybe it is a good starting point…

2)You can call the player controller script with something like GetComponent("PlayerControllerScript’).active = false; I recommend reading about the GetComponent method, you are going to use it overtime

  1. Transform.position = Vector3(x,y,z); in C # you will have to use the “new” keyword

4)For the last one, you can create a second scene called loaderScene. In that scene, create a script called myLoader and in the Start even of myLoader script place some code that would load your original scene using the application.loadlevel. Now when your player has died and you want to reload the game, just call your loaderScene and it will unload your current, reload the loader and reload your game from the start.

hope this helped