Setting up a function for sorting specific triggers entered based on a height integer.
I'm still working on a 2D game that involves a height system controlled by an integer.
The ground has triggers which assign the player with the appropriate height integer when the player enters the height trigger. This trigger's height value is added to a list on entry and removed on exit. If the player enters multiple height triggers multiple height integers should be stored in the list and sorted in order of highest value to lowest value. Then the height value that is highest is returned so that it can be assigned to the player.
e.g. 8573 -> 8753 with 8 being returned.
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GroundLvlAssign : MonoBehaviour 
 {
     public delegate void SetGroundLvlDelegate(int num);
     public SetGroundLvlDelegate setGroundLevelDelegate;
     public int SetGroundLvl = 1;//gives object a ground level
     
     void Start ()
     {
         setGroundLevelDelegate(SetGroundLvl);
     }
 }
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GroundColliderSort : MonoBehaviour
 {
 
     PlayerStatistics m_PlayerStatistics; //PlayerStatsScript
     GameObject Player; //GameObject
     
     int GroundHeightComponent;
     int HighestGroundHeightComponent;
     
     
     
     private List<int> GroundCollidersInside = new List<int>();
     
     void Awake()
     {
         //Get Craig Game Object
         Player = GameObject.FindGameObjectWithTag("Player");
         //Get Player Stats Script
         m_PlayerStatistics = Player.GetComponent<PlayerStatistics> ();    
     }
     
     //requires delegates
     //public int OnTriggerEnter2D (Collider2D ground)
     //{
         //GroundHeightComponent = ground.GetComponent<GroundLvlAssign>().SetGroundLvl;
         //if(GroundHeightComponent != null && !GroundCollidersInside.Contains(GroundHeightComponent))
         //{
             //GroundCollidersInside.Add(GroundHeightComponent);
             //GroundCollidersInside  = GroundCollidersInside.Sort(g => g.GroundHeightComponent).ToList();
             //HighestGroundHeightComponent = GroundCollidersInside(0);
             //return HighestGroundHeightComponent;
         //}
     //}
     
     void OnTriggerExit2D(Collider2D ground)
     {
         if(GroundHeightComponent != null && !GroundCollidersInside.Contains(GroundHeightComponent))
         {
             GroundCollidersInside.Remove(GroundHeightComponent);
         }
     }
 }
The playerstatistics script is only used for accessing the player's set height value.
if you need to ask anything let me know.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                