Hello,
I wrote this script that draws a box on the screen with the mouse, like RTS games.
How can I select every object that is inside this box?
In other words, how can I access these objects and change their variables?
#pragma strict
var MenuSkin : GUISkin;
private var clickPosX : float;
private var clickPosY : float;
private var CurPosX : float;
private var CurPosY : float;
private var drawing : boolean;
function Update() {
if(Input.GetMouseButtonDown(0))
{
drawing = true;
clickPosX = Input.mousePosition.x;
clickPosY = Input.mousePosition.y;
}
if(Input.GetMouseButton(0))
{
CurPosX = Input.mousePosition.x;
CurPosY = Input.mousePosition.y;
}
if(Input.GetMouseButtonUp(0))
{
drawing = false;
}
}
function OnGUI() {
GUI.skin = MenuSkin;
if(drawing && clickPosX != CurPosX)
{
GUI.Box (Rect (clickPosX, Screen.height - clickPosY, CurPosX - clickPosX, Screen.height - CurPosY - (Screen.height - clickPosY)), "");
}
}