I am using rays to get a point that I click and make an object appear at the point. However I noticed that when this happened the object appeared fairly close to the origin and just slightly off center in the direction of the mouse but not anywhere near the mouse itself. Thus I worked out some numbers and wrote this code in order to test where to place the GameObject in scene. But when I ran it, Unity crashed.

voidPlaceGoStone(Rayray){

floatx=0;

floatz=0;

floatmaxX=0.158f;

floatmaxZ=0.168f;

floatdistanceX=maxX/((boardSize-1)/2);

floatdistanceZ=maxZ/((boardSize-1)/2);

boolconditionX=true;

boolconditionZ=true;

boolonBoard=true;

intcountX=0;

intcountZ=0;

while(conditionX){

countX++;

if(ray.origin.x>maxX || ray.origin.x<maxX*-1){

onBoard=false;

conditionX=false;;

}

if(ray.origin.x>=0){

if(ray.origin.x<distanceX*countX){

conditionX=false;

}

}

elseif(ray.origin.x<0){

if(ray.origin.x>distanceX*countX*-1){

conditionX=false;

countX=countX*-1;

}

}

}

while(conditionZ){

countZ++;

if(ray.origin.z>maxZ || ray.origin.z<maxZ*-1){

onBoard=false;

conditionZ=false;

}

if(ray.origin.z>=0){

if(ray.origin.z<distanceZ*countZ){

conditionX=false;

}

}

elseif(ray.origin.z<0){

if(ray.origin.z>distanceZ*countZ*-1){

conditionX=false;

countZ=countZ*-1;

}

}

}

x=(distanceX*countX);
z=(distanceZ*countZ);

if(onBoard){

GameObjectstone=(GameObject)Instantiate(blackStone,newVector3(x,0.11f,z),transform.rotation);

stone.transform.Rotate(90.0f,0,0);

}

}