I have been trying to instantiate a prefab at the position of the cursor, like this:
However the when I click the prefab isn’t instantiating at the exact position of the cursor, It is off most always and sometimes it won’t even show up in front of the camera.
my code is:
function Update () {
var MousePosition = Input.mousePosition;
if (Input.GetMouseButtonDown(0))
{
var ObjectPosition = Camera.main.ScreenToWorldPoint(MousePosition);
ObjectPosition.y = 0;
Instantiate(Object, ObjectPosition, Quaternion.identity);
}
}
This script is attached to the Main Camera if that helps any. I am trying to instantiate the prefab on a plane, also.
