I’m working on my RTS thing, and I’m totally new to ray casting. I have multiple unit selection working, but for some reason, I can’t get single unit selection working. I can get the transform by the RaycastHit (I know because I did a print(hit.transform.name and it worked fine)) but for some reason, my code isn’t able to change the static variable to be true or false.
Here is the pertinent Camera code:
var tmpHit:RaycastHit;
var ray = Camera.main.ScreenPointToRay(new Vector3(mouse.x, mouse.y));
Physics.Raycast(ray,tmpHit);
var script:allunits = tmpHit.transform.GetComponent("allunits");
script.Select();
and here is the allunits code:
static var selected:boolean = false;
function Update ()
{
if(RTScamera.clicking)
{
//Multiple Select code
selected = RTScamera.isBetween(RTScamera.tl,RTScamera.br,new Vector2(transform.position.x, transform.position.z));
transform.Find("selected").renderer.enabled = selected;
}
}
static function Deselect():void
{
selected = false;
}
static function Select():void
{
selected = true;
}
static function isSelected():boolean
{
return selected;
}
EDIT:
Oh, and I know that if I named each object a different name then it would be a little easier, but I think it’d be more complex later down the line as instantiating units from buildings will be required.