I am making a click and drag camera movement script and have run into a road block. i feel that i do not know enough about what i am doing with the local variables to figure this out on my won.
My error: error CS0165: Use of unassigned local variable `Origin’
it is telling me that my last Line 22 is using Origin, witch is not assigned, but four lines above it, i clearly define it with Line 17.
void ClickDrag(){
print("Click");
Ray ray;
RaycastHit hit;
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, 100.0f))
{
print("Ray hit");
if (hit.collider.tag != "Flag"){
Vector3 ResetCamera;
Vector3 Origin;
Vector3 Diference;
bool Drag=false;
Diference=(Camera.main.ScreenToWorldPoint (Input.mousePosition))- Camera.main.transform.position;
if (Drag==false){
Drag=true;
Origin=Camera.main.ScreenToWorldPoint (Input.mousePosition);
} else {
Drag=false;
}
if (Drag==true){
Camera.main.transform.position = Origin-Diference;
}
}
}
}
what do change to make this work?