c# - Use of unassigned local variable in Unity -
here script control movement of shots.. error:
error cs0165: use of unassigned local variable `floorhit'
how can fix it?
void start(){ floor = layermask.getmask ("floor"); ray ray = camera.main.screenpointtoray (input.mouseposition); raycasthit floorhit; vector3 playermouse = floorhit.point - transform.position; playermouse.y = 0f; moveto (playermouse.x, playermouse.z); }
the value of ray needs set adding line
if (physics.raycast (ray, out floorhit)) { //add logic here if hit } just after declaring it.
so full example is
void start(){ floor = layermask.getmask ("floor"); ray ray = camera.main.screenpointtoray (input.mouseposition); raycasthit floorhit; if (physics.raycast (ray, out floorhit)) { vector3 playermouse = floorhit.point - transform.position; playermouse.y = 0f; moveto (playermouse.x, playermouse.z); } }
Comments
Post a Comment