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

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -