- Home /
Objects moving outside of camera
Hi I've been trying to make a click and drag for 2d objects but when I click the object it goes outside of the camera's view and I've tried moving the objects and camera to 0,0 but it still happens
Script for the camera #pragma strict function Update() { if (Input.GetMouseButtonDown(0)){
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
var screenToSceneRatio = Screen.height/(GetComponent.<Camera>().orthographicSize*2);
if (Physics.Raycast (ray,hit,100)) {
hit.transform.position.x = (Input.mousePosition.x - Screen.width)/screenToSceneRatio;
hit.transform.position.y = (Input.mousePosition.y - Screen.height)/screenToSceneRatio;
}
} }
any help is appreciated
Comment