here is my script, It is suposed to spawn a prefab at the mouse’s curent position,
var box : Transform;
var pos : Vector3;
function Update () {
if (Input.GetMouseButtonDown(0)){
pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Instantiate(box,pos, Quaternion.identity);
}
}
Can someone help?
It helps if you tell us what it’s doing wrong. Is it not instantiating? Is it throwing an error? Is it instantiating, but in the wrong place?
It’s spawning the prefab in the same spot no matter where I click
The value from your ScreenToWorldPoint function is always the same.
It may work better to raycast it. The function you’re using always picks a point on the camera’s near clipping plane, which is, by default, 0.3 units away from the camera.
Try something like this (untested code):
void Update () {
// lower-case 'c' in 'camera' - common error
var ray : Ray = camera.ScreenPointToRay (Vector3(200,200,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, Mathf.Infinity)) {
Instantiate(prefab, hit.point, Quaternion.identity);
}
}
Make sure you have some kind of collider to click on for this to work.
Fine, if we are spoon-feeding code:

var box : Transform;
function Update ()
{
if (Input.GetMouseButtonDown(0))
{
var mousePos : Vector3 = Input.mousePosition;
mousePos.z = 10.0;
var worldPos : Vector3 = camera.ScreenToWorldPoint(mousePos);
Debug.Log("Mouse pos: " + mousePos + " World Pos: " + worldPos + " Near Clip Plane: " + camera.nearClipPlane);
clone = Instantiate(box, worldPos, Quaternion.identity);
}
}
The ray-cast to a collider of some description is a better solution, but this works if all you want to do is slap down cubes on a flat plane. You can adjust the Z to be closer (smaller values) or further away (larger values) as you choose. If you use the camera near clip plane directly then the cubes will appear but will instantiate almost directly on your camera, i.e. your camera will be placed inside of the cubes so you won’t ever see them in the game view, only in the scene view.
That’s why I made it so abstract. That code will (probably) work as-is, but it would need some serious overhaul to be really useful.
But, point taken. 
I bow to your superior abstractness. Lesson learned. 
Thx for the scripts, they really helped with my game.