OnTriggerStay problem or alternative mode
Hi guys, i'm an italian "programmer" i have a problem with my script. In few world i try to emulate LEAGUE OF LEGENDS tower functionality with my custom script and works at 80% more or less. The problem is that the difference between "LOL" and my idea is the runtime team change and for player and tower works when you change the team not in trigger, if you try to change when you are on the trigger this don't seems work. So if i have team1 change and select team2 not in trigger and the tower is set to attack only team1 when i re-enter on trigger the tower don't shoot me, if a change the team when i am into trigger the tower attack me ever if i keep team1,team2,team3. This is the script, i know that is more caotic but i hope in a help an maybe why not ,an upgrade of my script ;)
var team1 : boolean = false; var team2 : boolean = false; var team3 : boolean = false;
var target : GameObject; var minion : GameObject;
var minioninside : boolean = false;
var PlayerList : List. = new List.();
var oggetto : GameObject;
var MinionList : List. = new List.();
var reposizioning : boolean = false;
var numofplayer : int;
var numofminion : int;
function Start () { reposizioning = true; }
function Update () {
team1 = oggetto.gameObject.GetComponent(findenemy).team1; team2 = oggetto.gameObject.GetComponent(findenemy).team2; team3 = oggetto.gameObject.GetComponent(findenemy).team3;
numofminion = MinionList.Count; numofplayer = PlayerList.Count;
if(!target) { minioninside = true; }
if(numofminion <= 0) { minioninside = false; }
if(minioninside) { reposizioning = false; oggetto.transform.position = minion.transform.position; } else { if(target) { oggetto.transform.position = target.transform.position; } else { reposizioning = true; } }
if(minion.gameObject.GetComponentInParent(minionhealthbar).health <= 0) { MinionList.Remove(minion.gameObject); minion = null; }
if(!MinionList.Contains(minion.gameObject)) { minion = null; }
if(target.gameObject.GetComponentInParent(healthbar).health <= 0) { PlayerList.Remove(target.gameObject); target = null; }
if(!PlayerList.Contains(target.gameObject)) { target = null; } else {
if(team1)
{ if(target.gameObject.GetComponentInParent(clicktomove).ally1) { target = null; } }
if(team2) { if(target.gameObject.GetComponentInParent(clicktomove).ally2) { target = null; } }
if(team3) { if(target.gameObject.GetComponentInParent(clicktomove).ally3) { target = null;
} }
}
for (var vita : GameObject in PlayerList) { if(vita.gameObject.GetComponentInParent(healthbar).health <= 0) { PlayerList.Remove(vita.gameObject);
} }
for (var mostro : GameObject in MinionList) { if(mostro.gameObject.GetComponentInParent(minionhealthbar).health <= 0) { MinionList.Remove(mostro.gameObject);
} }
if(team1) { if(target.gameObject.GetComponentInParent(clicktomove).ally1) { target = null; } }
if(team2) { if(target.gameObject.GetComponentInParent(clicktomove).ally2) { target = null; } }
if(team3) { if(target.gameObject.GetComponentInParent(clicktomove).ally3) { target = null;
} }
if(!target) { if(team1) { for(var one : GameObject in PlayerList) { if(!one.gameObject.GetComponentInParent(clicktomove).ally1) { target = one.gameObject; } } }
if(team2)
{
for(var two : GameObject in PlayerList)
{
if(!two.gameObject.GetComponentInParent(clicktomove).ally2)
{
target = two.gameObject;
}
}
}
if(team3)
{
for(var three : GameObject in PlayerList)
{
if(!three.gameObject.GetComponentInParent(clicktomove).ally3)
{
target = three.gameObject;
}
}
}
}
}
function OnTriggerEnter (first : Collider) { if(first.gameObject.tag == "Cube") {
if(first.gameObject.GetComponentInParent(healthbar).health > 0)
{
if(!PlayerList.Contains(first.gameObject))
{
PlayerList.Add(first.gameObject);
}
if(!target)
{
if(team1)
{
if(!first.gameObject.GetComponentInParent(clicktomove).ally1)
{
target = first.gameObject;
}
}
if(team2)
{
if(!first.gameObject.GetComponentInParent(clicktomove).ally2)
{
target = first.gameObject;
}
}
if(team3)
{
if(!first.gameObject.GetComponentInParent(clicktomove).ally3)
{
target = first.gameObject;
}
}
}
}
}
if(first.gameObject.tag == "minioncube")
{
if(first.gameObject.GetComponentInParent(minionhealthbar).health > 0)
{
if(!MinionList.Contains(first.gameObject))
{
MinionList.Add(first.gameObject);
}
if(!minion)
{
minion = first.gameObject;
}
}
if(target == null)
{
minioninside = true;
}
}
}
function OnTriggerExit( third : Collider) {
if(third.gameObject.tag == "Cube")
{
if(third.gameObject.GetComponentInParent(healthbar).health > 0)
{
if(PlayerList.Contains(third.gameObject))
{
if(target == third.gameObject)
{
PlayerList.Remove(third.gameObject);
target = null;
}
else
{
PlayerList.Remove(third.gameObject);
}
}
}
}
if(third.gameObject.tag == "minioncube")
{
if(third.gameObject.GetComponentInParent(minionhealthbar).health > 0)
{
if(MinionList.Contains(third.gameObject))
{
MinionList.Remove(third.gameObject);
}
}
}
}
Thanks to all guys for every answer i receive
Cheers.
Your answer
Follow this Question
Related Questions
Why when i change a scene things doesn't change? 0 Answers
Unity won't start properly 0 Answers
Falling Object Trigger Problem 1 Answer
How to fix button triggers after upgrade to 5.2.3f1 Personal 1 Answer