// 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));
}
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);
}
}