Hi there i was wondering if anyone could help with my piece of code.
this script can select units now and deselect them with right mouse button
but when i got one unit selected it wont select another unit and deselect the current selected unit

Can someone help me fix it so that when i click another unit it deselects the current unit and selects the other unit ?
Thnx in advance
Here is my code
//////////////////////////////
// Ingame Unit Control
//////////////////////////////
//var Unit_Selected[30]; //cant store entity in array...
var own_unit;
var secondtry;
string bmp_selected, <Selected.bmp>;
function highlight_me()
{
if (event_type == event_click)
{
play_random_snd_hfx();
if(own_unit==0)
{Selection();secondtry=1;}
}
if (event_type == event_touch)
{
my.ambient = 100;
}
while (event_type != event_release) {wait (1);}
my.ambient = 0;
}
function DoubleCheck()
{
while(1)
{
if(own_unit==1&&secondtry==1)
{
ent_remove(me);
}
wait(1);
}
}
function Selection()
{
if (!own_unit == 1)
{
me = ent_create (bmp_selected,vector (my.x,my.y,my.z-15 ),DoubleCheck());
me.tilt = 90;
own_unit = 1;
while(!mouse_right)
{
me.pan +=-0.2;
wait(1);
if(mouse_right)
{
own_unit = 0;
secondtry = 0;
ent_remove(me);
}
}
}
}
action my_unit
{
my.enable_touch = on;
my.enable_click = on;
my.enable_release = on;
my.event = highlight_me;
}
//////////////////////////////
// End
//////////////////////////////