spawning a box collider

var projectile : Rigidbody;
var speed = 20;
function Update()
{
 if( Input.GetButtonDown( "Fire1" ) )
  {
  var instantiatedProjectile : Rigidbody = Instantiate( 
   projectile, transform.position, transform.rotation );
  instantiatedProjectile.velocity =
   transform.TransformDirection( Vector3( 0, 0, speed ) );
  Physics.IgnoreCollision( instantiatedProjectile. collider,
   transform.root.collider );
  }
}

i want it so that i can spawn a box without a rigidbody but i am not sure how to take the rigidbody away inside the script.

Here you go.

// attach cube with rigidbody to cube_pfb var.
var cube_pfb:GameObject;

function Start () {
	var newCube:GameObject =  Instantiate(cube_pfb, Vector3(20,20,20), transform.rotation);
	Destroy (newCube.GetComponent (Rigidbody));
}

Regards.

It is working 100%.
Try this in empty scene for test purposes.
Don’t forget to drag some object to cube_pfb var.

If all you want is to spawn a cube in front of the camera, add this script to the camera:

function Update(){
  if( Input.GetButtonDown( "Fire1" ) ){
    var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
    // set the position 1 meter ahead of the camera
    cube.transform.position = transform.position + transform.forward;
    cube.transform.rotation = transform.rotation;
  }
}

If you want to instantiate an arbitrary object, use this:

var prefab: Transform; // drag the object here

function Update(){
  if( Input.GetButtonDown( "Fire1" ) ){
    Instantiate(prefab,transform.position+transform.forward,transform.rotation);
  }
}

thank you for both of your scripts they both work but i find that Aldon’s script works the best.