add building in RTS

Hello, I work on a RTS game (like age of empire), but i don't know how to add a building when the game is running. Can you help me with some scripts? Can you help me?

Use a mouse point to ray to check for where you clicked and then instantiate a building there:

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
    Debug.DrawLine (ray.origin, hit.point);
    Instantiate(buildingTypes[buildIndex],hit.point,Quaternion.identity);
}

EDIT

To place several types of building you can store building prefabs in a game object array. Declare it like so:

var buildingTypes : GameObject[];

This will turn into a drop down menu in the inspector where you can drag prefabs of mills, barracks, houses etc.

You need to be able to pick which building to instantiate so you store your selection in an int variable like buildIndex which you declare like so:

var buildIndex : int = 0;

Array indexing starts at 0 so the first item in the list will be buildingTypes[0]

Next you need a way to change the index so you might have a bunch of GUI Icons showing a picture of the building. You set up GUI icons like so:

function OnGUI(){
   if(GUI.Button(Rect(0,0,40,20),"Mill")){
      buildIndex = 1; // if the mill prefab is the second item in the array
   }
}

Next you might want to stop the player spamming buildings so you'll do a cost for each building. You'll have to store costs in some variable as well as how much resources you have. e.g. for wood you might do:

var resourceWood : int = 100;

function Build(buildingType : int){
   if(buildingType==1){
      // you want to build a mill, they cost 50 wood
      if(resourceWood>50){ // do we have more than 50 wood?
         resourceWood-=50;
         // do the above mouse to ray and insatiate script here
      }
   }
}

That's not even the tip of the iceberg but I hope it sets you on the right path to writing your own game.

http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html

i wrote something like these :

var buildingTypes : GameObject[];
var buildIndex : int = 0;
var resourceWood : int = 100;

function Update () {

var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100)) {
    Debug.DrawLine (ray.origin, hit.point);
    Instantiate(buildingTypes[buildIndex],hit.point,Quaternion.identity);
}
}

function OnGUI(){
   if(GUI.Button(Rect(0,0,40,20),"Mill")){
      buildIndex = 1; 
   }
}

function Build(buildingType : int){
   if(buildingType==1){
      // you want to build a mill, they cost 50 wood
      if(resourceWood>50){ 
         resourceWood-=50;
         // do the above mouse to ray and insatiate script here
      }
   }
}

it gives me an error, it says :

NullReferenceException: Object reference not set to an instance of an object NewBehaviourScript 1.Update () (at Assets\NewBehaviourScript 1.js:7)