I have written code for a loop to create objects in a select area based off mouse position A and Mouse position B. but the problem i have come across is that it only works is if point1 is to the right of and lower to point2, How can write this correctly?
var point1 : Vector3;
var point2 : Vector3;
var z : float;
var ray : Ray; //Camera.main.ScreenPointToRay(Input.mousePosition);
if (Input.GetMouseButtonDown(0) && box2)
{
point1= ray.origin + (ray.direction*distanc);
point1.y = hieghtFloor;
point1.z = Mathf.RoundToInt(point1.z);
z = point1.z;
point1.x = Mathf.RoundToInt(point1.x);
pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
Debug.Log("Point "+pointStr1);
}
if (Input.GetMouseButtonUp(0)&& box2)
{
point2= ray.origin + (ray.direction*distanc);
point2.y = hieghtFloor;
point2.z = Mathf.RoundToInt(point2.z);
point2.x = Mathf.RoundToInt(point2.x);
pointStr2 = point2.x+","+ point2.y+","+point2.z;
var currentz : int = point2.z- point1.z;
var currentx : int = point2.x-point1.x;
var maxInt : int = currentz*currentx;
if(maxInt > 0)
{
for(var i = 0;i <= currentx; i++)
{
for(var t = 0 ;t <= currentz; t++)
{
if(!GameObject.Find(pointStr1) && !GameObject.Find(pointStr2))
{
currentObj=GameObject.Instantiate (startCube,point1, Quaternion.identity);
pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
currentObj.name = point1.x+","+ point1.y+"1,"+point1.z;;
}
point1.z++;
pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
}
point1.x++;
point1.z = z;
pointStr1 = point1.x+","+ point1.y+"1,"+point1.z;
}
}