blood damage like call of duty?

Hi guys,

Is it possible in Unity to make the health as blood damage like in call of duty?

I mean like this image:

http://img.gamespot.com/gamespot/images/2009/315/reviews/951942_20091112_embed004.jpg

Thanks in advance

You should use one or more GUITexture, and control its color.a property according to the player’s health, like @anwe said. It’s better to use two or three GUITexture, each one with a different blood splash pattern. Each GUITexture must start appearing at a different health level, thus the screen will become more and more bloody while the player life is going away.

You could do the following: create the blood images with transparent background, and import them using Assets/Import New Asset; select each image in Project and click GameObject/Create Other/GUITexture - this will create a GUITexture with the selected image; drag the GUITextures created to each bloodGuiN variable in the script below:

var bloodGui1: GUITexture; // drag here the GUITextures you've created:
var bloodGui2: GUITexture; // bloodGui1 should have the lower blood density,
var bloodGui3: GUITexture; // and bloodGui3 the higher density.

function Start(){ 
  // set GUITexture.pixelInset to the whole screen:
  var r = Rect(-Screen.width/2, -Screen.height/2, Screen.width, Screen.height);
  bloodGUI1.pixelInset = r;
  bloodGUI2.pixelInset = r;
  bloodGUI3.pixelInset = r;
}

// Returns the alpha value proportional to the health loss;
// "start" tells the health percentage below which the blood starts appearing
function BloodAlpha(start: float): float {
    var alpha = 1 - (100 * health)/(start * normalHealth);
    return Mathf.Clamp(alpha, 0, 1);
}

function Update(){
  bloodGUI1.color.a = BloodAlpha(100); // start appearing when health < 100%
  bloodGUI2.color.a = BloodAlpha(60); // start appearing when health < 60%
  bloodGUI3.color.a = BloodAlpha(30); // start appearing when health < 30%
}

NOTE: this script assumes that health contains the current player health, and normalHealth is the max health under normal conditions (no extra health). Change these names to the ones you are actually using. If both are static variables, you can use this code in a separate script; if not, add this code to your health script or wherever these variables are declared.

of course, just try to put a texture or a plane over the camera and modify its alpha component of color, so that u can’t see it if u have got 100 health, but if u’ve got jut 10 u’ll see the blood damage