Script to make gameObject follow another gameObject!

Can someone explain me how to do that a gameObject follow another gameObject with the function OnCollisionEnter or OnTriggerEnter?
I use both c# and java.

This is an extremely easy script to make an enemy follow the player, as long as he is in range (JavaScript):

#pragma strict

var detRange : float;
var speed : float; 

private var plChar : GameObject;

function Start () {
	plChar = gameObject.FindWithTag("Player");
}

function Update () {
	if((plChar.transform.position - transform.position).magnitude > 1 && (plChar.transform.position - transform.position).magnitude < detRange) {
		transform.LookAt(plChar.transform.position);
		transform.Translate(Vector3.forward * speed);
	}
}

Just parent the GameObject you want following the other GameObject to that other GameObject and it’ll follow it when it moves.

Edit: That sounds confusing, so here’s the example hierarchy:

MainObject
    Follower
    Follower
    Follower

Move “MainObject” and all the "Follower"s will move with it.

No. the gameObject must follow the other gameObject with an higher speed in in another moment of the game.

Somthing like this?

void OnTriggerEnter(Collider other){
        if(other.name == "Example"){
            Start to follow.. 
        }
}

#pragma strict
var target: Transform; // drag the target here
var speed: float = 5.0; // object speed
private var moving = false; // object initially stopped
private var dir: Vector3;
private var plChar : GameObject;
function Start () {
}

    function Update () {
        dir = target.position - transform.position; // calculate the target direction...
        moving = true; // and enable movement
     
      if (moving){ // if movement enabled...
        // move the object in the calculated direction (world coordinates):
        transform.Translate(dir * speed * Time.deltaTime, Space.World);
      }
    
    
    
    }