Instantiate object at touch position problem

Hello everyone! i have a problem with an android game: i’ve written this code to instantiate a prefab at the touch position but the object (a projectile) is always instantiated at the center of the screen. What’s wrong?

function Update () {
	for (var i = 0; i < Input.touchCount; ++i) {
        if (Input.GetTouch(i).phase == TouchPhase.Began) {
        	var touchPos = Input.GetTouch(i).position;
	        var createPos = myCam.ScreenToWorldPoint(touchPos);
	        Instantiate (projectile, Vector3(createPos.x, createPos.y, 4), Quaternion.identity);
       	}
    }
}

The most likely issue is that you are not setting the ‘z’ coordinate of touchPos before calling myCam.ScreenToWorldPoint(). ‘Z’ is how far in front of the camera to create the position. Try this (untested):

function Update () {
    for (var i = 0; i < Input.touchCount; i++) {
        if (Input.GetTouch(i).phase == TouchPhase.Began) {
            var touchPos : Vector3 = Input.GetTouch(i).position;
            touchPos.z = 4.0;
            var createPos = myCam.ScreenToWorldPoint(touchPos);
            Instantiate (projectile, createPos, Quaternion.identity);
        }
    }
}