I’m still having problems. I have a system in which there are triggers with an assigned height variable. When the player enters one of these triggers, it’s value is added to a list, which is then sorted and the highest value is assigned to the player. However I need to ensure that when the player exits one of these triggers, the list item corresponding to the exited colliders number should be removed.
Here is the code for entry:
void OnTriggerEnter2D (Collider2D ground)
{
GroundHeightComponent = ground.GetComponent<GroundLvlAssign>().SetGroundLvl;
if (ground.gameObject.GetComponent<GroundLvlAssign>().SetGroundLvl != m_PlayerStatistics.m_PlayerGroundLvl)
{
m_PlayerStatistics.m_PreviousPlayerGroundLvl = m_PlayerStatistics.m_PlayerGroundLvl;
m_PlayerStatistics.m_PlayerGroundLvl = HighestGroundHeightComponent;
}
}
Staying:
void OnTriggerStay2D (Collider2D ground)
{
//If ground is not the same set Previous ground level to player ground level and then set current ground level to floor ground level
if(GroundHeightComponent != null && !GroundCollidersInside.Contains(GroundHeightComponent))
{
GroundCollidersInside.Add(GroundHeightComponent);
GroundCollidersInside.Sort();
HighestGroundHeightComponent = GroundCollidersInside[GroundCollidersInside.Count - 1];
}
}
Exiting (Not working as intended):
void OnTriggerExit2D(Collider2D ground)
{
//check through all of the numbers colliders inside list to check for if they matchthe collider you exited's number snd then remove them
for (int i=0;i<GroundCollidersInside.Count;++i)
{
if(GroundCollidersInside *== ground.gameObject.GetComponent<GroundLvlAssign>().SetGroundLvl && GroundCollidersInside.Contains(i))*
-
{*
-
GroundCollidersInside.Remove(i);*
-
GroundCollidersInside.Sort();*
-
HighestGroundHeightComponent = GroundCollidersInside[GroundCollidersInside.Count - 1];*
-
}*
-
}*
-
if (ground.gameObject.GetComponent<GroundLvlAssign>().SetGroundLvl != m_PlayerStatistics.m_PlayerGroundLvl)*
-
{ *
-
m_PlayerStatistics.m_PlayerGroundLvl = HighestGroundHeightComponent;*
-
}*
- }*
I have a good Idea why the exit code doesn’t work as intended, but what I don’t know is how to make sure that on exit of a trigger, that the list item that matches the exited trigger’s height value is removed.