I set the variable “hit” but is says I didn’t so I dont know whats wrong with it.
public GameObject Cube;
void Update()
{
if(Input.GetKey(KeyCode.Mouse0))
{
RaycastHit Hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Cube.transform.position = (Hit.point);
}
}
error : error CS0165: Use of unassigned local variable `Hit’
There is nothing here that assigns a value to the ‘hit’ variable, so that is why you are getting the error. Usually there is a Raycast() in this code that assigns the value. Something like this inserted on line 10:
if (Physics.Raycast(ray, out hit) {
Cube.transform.position = hit.point;
}
The ‘out’ specifies that ‘hit’ will be changed by the function.
You create the variable but it’s not initialised (you don’t assign anything to it).
You also never run an actual raycast to check what the ray from the mouse input is hitting.
You should probably look here: http://docs.unity3d.com/ScriptReference/Physics.Raycast.html and check the versions that use RaycastHit.