How to get player to lose health by default?

I apologise as I’m completely new to Unity, but how would I go about scripting the game such that when the first person controller is not colliding with an object, the player is losing health at a steady rate. However, when the player is colliding with the object, the player would regenerate their lost health. Any help is greatly appreciated.

to make this realy easy just create a variable, to storage the life percentage:
var life : float = 10.0f;

there is a funcion, called OnCollisionEnter (i suggest you to see in scripting reference) where you can get info about collision.
function OnColliderEnter (collisionInfo : collider) {
if (collider.tag == “enemy”) {
life -= .5f;
}
}

in this function we have wrote that if you have collided an object with tag “enemy” then decrease the life of 0,5, we have wrote the “f” after .5f, because it is a cast. you will learn it later. If you need for help, send me a message.
Good luck, and welcome to unity

Here is a little something that should help you get started.

var health : int = 100;

function OnTriggerEnter(){

   if (health != 100){
      yield WaitForSeconds (1);
	  health += 1;
	}
}

function OnTriggerExit(){

   if (health != 0){
      yield WaitForSeconds (1);
	  health -= 1;
	}
}

function Update(){

   if (health == 0){
      print ("You have died");
	}
}

All it does is when the player has entered a trigger, it adds 1 health every second, until health = 100.
When the player has left the trigger, it subtracts 1 health every second, until health = 0.
When health = 0, it prints a message saying that you have died.

It hasn’t been tested but it should work.

P.S. In order for this to work, on the object you wish to collide with the isTrigger box needs to be ticked.
You will find this in the objects collider settings.

If you do not wish to use triggers, just change function OnTriggerEnter to function OnCollisionEnter
Do the same thing with function OnTriggerExit

Hopefully I have not confused you too much.

This will happen just 1 time. He needs to use something like InvokeRepeating() and CancelInvoke().

http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.InvokeRepeating.html
http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.CancelInvoke.html

Would the code work if I were to put two of those functions inside the function Update() ? Like this:

function Update() {

   function OnTriggerEnter(){
      if (health != 100){
         yield WaitForSeconds (1);
         health += 1;
       }
   }
   function OnTriggerExit(){
      if (health != 0){
         yield WaitForSeconds (1);
         health -= 1;
       }
   }
}

No. I recommend you to look for a basic programming tutorial.