Getting hit.

I need a script that when an enemy shoots and I get hit by the object, it’ll go to the next guitexture, to lower my health bar.

var healthImages : Texture2D[];
var player : transform;
var GUIPos : Rect;
private var health : int;

function OnGUI () {

health = player.GetComponent("PlayerStats").health;

GUI.Label(GUIPos, healthImages[health - 1]);

}

This post was continued on this tread.
http://forum.unity3d.com/viewtopic.php?t=46382&highlight=