Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

HUD Radar hoping this could help anyone

Discussion in 'Immediate Mode GUI (IMGUI)' started by Kardux, May 14, 2013.

  1. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    Well after working during two days on it (yeah i'm new to Unity so maybe some of you may be able to achieve this in an hour :p), I finally ended doing something good that works well !

    My project was to create a kind of HUD (Head-Up Display) that could focus items in your scene (for me the items you can interact with).
    I have to warn you that I still guess I've done some things in a weird way so they could have been much simpler !

    Anyway thanks to robertbu for his help and here's my script (that I fully commented for more understanding) if it can be useful to any future visitor : Feel free to use on your own ;)

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;               //Use this so you can manipulate Lists
    4.  
    5. public class GUIRadar : MonoBehaviour
    6. {
    7.     public Texture2D targetIcon;                //The target icon that will be placed in front of targets
    8.     public float maxTargetIconSize = 300f;      //The maximum size of icons when close to the target
    9.     public float minTargetIconSize = 0f;        //The minimum size of icons when they appear (far from the target)
    10.     public float maxDistanceDisplay = 10f;      //The maximum distance from where you can see the icons appearing
    11.     public float minDistanceDisplay = 2f;       //The minimum distance from where you see the icons disappearing when too close
    12.     public float smoothGrowingParameter = 25f;  //The speed of the growing effect on icons
    13.     public float smoothMovingParameter = 25f;   //The moving speed of items : high values means the icon is "attached" to the item
    14.     public bool directViewEnabled = true;       //If you want to allow icon display even if targets aren't in direct view for the player
    15.    
    16.     public struct TargetStruct                  //Structure that contain every icon informations
    17.     {
    18.         public GameObject item;                 //-the item the icon is linked to
    19.         public Vector3 screenPos;               //-the screen position of the icon (!= world position)
    20.         public float xSize, ySize;              //-the current size of the icon on the screen
    21.         public float xPos, yPos;                //-the current coordinates of the screen position
    22.         public float xTargetSize, yTargetSize;  //-the coordinates you want the icon to reach
    23.         public float xTargetPos, yTargetPos;    //-the size you want the icon to reach on the screen
    24.         public float distance;                  //-the distance between player and the item linked to the icon
    25.         public bool directView;                 //-tells you if the item is in direct view or not
    26.     }
    27.    
    28.     public List<TargetStruct> TargetList = new List<TargetStruct>();//Your ICONS LIST
    29.     public GameObject[] Targets;                                    //The GameObjects considered as targets
    30.    
    31.     private int targetsCount;                                       //Number of targets in the scene
    32.    
    33.     void Awake()                                                       
    34.     {
    35.         Targets = GameObject.FindGameObjectsWithTag(/**/Tags.interact/**/);     //Get all the potential targets in the scene (just replace it by your own tag : "MyTag")
    36.        
    37.         foreach(GameObject target in Targets)                                   //Put every detected GameObject into your ICONS LIST
    38.         {
    39.             TargetStruct newTarget = new TargetStruct();
    40.             newTarget.item = target;                                            //and attach each icon its GameObject
    41.             TargetList.Add(newTarget);
    42.         }
    43.        
    44.         targetsCount = TargetList.Count;                                        //Count the number of target in the scene
    45.     }
    46.    
    47.     void Update()
    48.     {      
    49.         for(int i = 0; i<targetsCount; i++)                                                         //You have to repeat it for every icons : be aware that if you have too much that could use a lot of ressoures
    50.         {
    51.             TargetStruct target = new TargetStruct();                                               //You have to create a temporary TargetStruct since you can't access a variable of an element in a list directly
    52.             target = TargetList[i];                                                                 //You take the item attached to the icon
    53.            
    54.             target.screenPos = camera.WorldToScreenPoint(target.item.transform.position);           //Convert world coordinates of the item into screen ones
    55.             target.distance = Vector3.Distance(target.item.transform.position, transform.position); //Get the distance between item and player
    56.            
    57.             if(target.distance>maxDistanceDisplay || target.distance<minDistanceDisplay)            //If the item is too far or too close
    58.             {
    59.                 target.xTargetSize = minTargetIconSize;                                             //you want it to disappear
    60.                 target.yTargetSize = minTargetIconSize;                                             //or at least to be in its smaller size
    61.             }
    62.             else
    63.             {
    64.                 target.xTargetSize = maxTargetIconSize/(target.distance);                           //Else you get its size with the
    65.                 target.yTargetSize = maxTargetIconSize/(target.distance);                           //distance : far<=>small / close<=>big
    66.                
    67.             }
    68.        
    69.             if(target.distance>maxDistanceDisplay)                                                  //If the item is too far, you set its screen position : (this way it seems as if the icon was coming away from the screen to focus your target)
    70.             {
    71.                 if(target.screenPos.x<Screen.width/2)                                               //-if it's under the center of the view field
    72.                     target.xTargetPos = 0;                                                          //to the bottom of the screen
    73.                 else                                                                                //-else
    74.                     target.xTargetPos = Screen.width;                                               //to the top of the screen
    75.                
    76.                 if(target.screenPos.y<Screen.height/2)                                              //-if it's on the right of the view field
    77.                     target.yTargetPos = Screen.height;                                              //to the right of the screen
    78.                 else                                                                                //-else
    79.                     target.yTargetPos = 0;                                                          //to the left of the screen
    80.             }
    81.             else                                                                                    //If the item is NOT too far, you set its screen position :
    82.             {
    83.                 target.xTargetPos = target.screenPos.x-target.xSize/2;                              //in x-axis to the item's x-position minus half of the icon's size
    84.                 target.yTargetPos = Screen.height-target.screenPos.y-target.ySize/2;                //in y-axis to the item's y-position minus half of the icon's size
    85.             }
    86.            
    87.             target.xSize = Mathf.Lerp(target.xSize, target.xTargetSize, smoothGrowingParameter*Time.deltaTime); //You do lerps on your icons size so you can adjust
    88.             target.ySize = Mathf.Lerp(target.xSize, target.yTargetSize, smoothGrowingParameter*Time.deltaTime); //the speed of their resizing
    89.            
    90.             target.xPos = Mathf.Lerp(target.xPos, target.xTargetPos, smoothMovingParameter*Time.deltaTime);     //You do lerps on your icons position so you can adjust
    91.             target.yPos = Mathf.Lerp(target.yPos, target.yTargetPos, smoothMovingParameter*Time.deltaTime);     //their moving speed
    92.            
    93.             RaycastHit hitInfos = new RaycastHit();                                                                 //You create a new variable to stock the information of the coming raycast
    94.             Physics.Raycast(transform.position, target.item.transform.position-transform.position, out hitInfos);   //and you RayCast from the player's position to the item's position
    95.            
    96.             if(hitInfos.collider.gameObject.layer==8)                                                               //HERE IS A BIT TRICKY : you have to creat new layers (I called them "Interactive Items" and "Obstacles") and to apply them to your various items.
    97.                 target.directView=true;                                                                             //Then you select EVERY items in your scene and set their layer to "Ignore Raycast". After that you select your interactive items biggest shape (if you have big trigger colliders on them select the item that hold it),
    98.             else                                                                                                    //and set their layers to "Interactive Items". Last part is setting every potential obstacle item layer to "Obstacles".
    99.                 target.directView=false;                                                                            //NOTE : Here my "Interactive Items" layer number is 8
    100.            
    101.             TargetList[i] = target;                                                                 //You apply all the variables to your index-i icon in the ICONS LIST
    102.         }
    103.     }
    104.    
    105.     void OnGUI()
    106.     {
    107.         for(int i = 0; i<targetsCount; i++)                                                                                             //For every icon
    108.         {
    109.             if(TargetList[i].screenPos.z>0  (!directViewEnabled || (directViewEnabled  TargetList[i].directView)))                  //If the icon is in front of you and all the required conditions are okay
    110.                 GUI.DrawTexture(new Rect(TargetList[i].xPos, TargetList[i].yPos, TargetList[i].xSize, TargetList[i].ySize), targetIcon);//you display the icon with it's size and position
    111.         }
    112.     }
    113. }
    And here's a quick screen of the in-game appearance :
    $HUD_Radar_Screen.png
     
  2. zeppeldep

    zeppeldep

    Joined:
    Jun 2, 2013
    Posts:
    27
    This looks to be exactly what I need ... Thx a stack ... busy trying to implement ... do you maybe have a demo scene handy?
     
  3. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    Well first I'm glad this is finally usefull to someone :D

    Here's a quick demo scene I just made to show how the script works in game (note that you can adjust a lot of parameters such as the moving speed of the cursor, its size, ...)

    You can download it here. Enjoy ! :wink:
     
  4. MajorParts

    MajorParts

    Joined:
    Sep 27, 2014
    Posts:
    64
    Hi

    Dunno if you still check here, but I have some questions.

    This looked to be what I was after, and I got it to work ok but not in the way I need.

    I am using it to target enemies, or at least show me their position, but then I destroy one of things it is targeting. This is where it goes wrong! Once the object has been destroyed, the target icons for it remains frozen on the screen, along with all the others that were being targeted.
    How would I go about removing the destroyed objects icon, leaving the others intact?

    The other thing, is I am wanting to use the icons on a forward and rear scanner, so I can get my bearings when looking for the targets. I have 2 scanner cameras, 1 in each top corner, and the script attached to both. My problem here is, if I rotate to face the other way, the icons drop off the camera and onto the main screen.

    Any idea what I have to do here?

    Cheers,
    John
     
  5. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    Well yes I'm still checking here to look for some improvements I could add to my script.

    I'm currently working on the two things you mentionned:
    - the update problem where the icon stayed on the UI has already been solved with a new function added to the code.
    - I found a way to bypass the problem you had using multiple cameras and I'm still scripting it: it should be done soon.

    I'll post my result asap. with a new version of the demo scene so you'll get how to use the new features.
     
  6. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    First sorry for this being a double post but here you go :
    - now you can call the DeleteTarget method from the radar script in order to suppress an item from the icons (this solves the first problem you had). Make sure to call this before destroying your GameObject since one of the method parameter is the item tagged with the RadarDetectable (or anything else now ;) ) tag.
    - also, th script now takes into consideration the viewport of the camera it's attached to and I added an alpha blending option in order to get the icons going from 1.0 alpha scale in the middle of the viewport to 0.0 on the edges. This way the icons kinda disapear when going otside of the viewport (note that you can adjust the effect with the alphaStartPercentage parameter).

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;                //Use this so you can manipulate Lists
    4.  
    5. public class GUIRadarTest : MonoBehaviour
    6. {
    7.     [SerializeField] private Texture2D targetIcon;                    //The target icon that will be placed in front of targets
    8.     [SerializeField] private float maxTargetIconSize = 300f;        //The maximum size of icons when close to the target
    9.     [SerializeField] private float minTargetIconSize = 0f;            //The minimum size of icons when they appear (far from the target)
    10.     [SerializeField] private float maxDistanceDisplay = 10f;        //The maximum distance from where you can see the icons appearing
    11.     [SerializeField] private float minDistanceDisplay = 2f;            //The minimum distance from where you see the icons disappearing when too close
    12.     [SerializeField] private float smoothGrowingParameter = 25f;    //The speed of the growing effect on icons
    13.     [SerializeField] private float smoothMovingParameter = 25f;        //The moving speed of items : high values means the icon is "attached" to the item
    14.     [SerializeField] private string tagToFollow = "RadarDetectable";
    15.     [SerializeField] private bool directViewOnly = true;            //If you want to allow icon display even if targets aren't in direct view for the player, set it to false
    16.     [SerializeField] private bool activateAlphaBlending = true;        //If alpha blending is needed when the icon approachs the camera viewport edges
    17.     [SerializeField] private float alphaStartPercentage = 0.2f;     //Indicates when the icon will start going from alpha=1 to alpha=0 (0.2 = 20% of the viewport size)
    18.  
    19.     public struct TargetStruct                    //Structure that contain every icon informations
    20.     {
    21.         public GameObject item;                    //-the item the icon is linked to
    22.         public Vector3 screenPos;                //-the screen position of the icon (!= world position)
    23.         public float xSize, ySize;                //-the current size of the icon on the screen
    24.         public float xPos, yPos;                //-the current coordinates of the screen position
    25.         public float xTargetSize, yTargetSize;    //-the coordinates you want the icon to reach
    26.         public float xTargetPos, yTargetPos;    //-the size you want the icon to reach on the screen
    27.         public float distance;                    //-the distance between player and the item linked to the icon
    28.         public bool directView;                    //-tells you if the item is in direct view or not
    29.         public float alpha;                        //-indicates the alpha level to apply to the icon texture
    30.     }
    31.    
    32.     private List<TargetStruct> TargetList = new List<TargetStruct>();//Your ICONS LIST
    33.     private GameObject[] Targets;                                    //The GameObjects considered as targets
    34.    
    35.     private int targetsCount;                                        //Number of targets in the scene
    36.  
    37.     private float cameraXSize;
    38.     private float cameraYSize;
    39.     private float cameraXPos;
    40.     private float cameraYPos;
    41.  
    42.     private Color guiGolor = Color.white;
    43.    
    44.     void Awake()                                                      
    45.     {
    46. //Check if the tag exists in the project
    47. #if UNITY_EDITOR
    48.         bool checkTag = false;
    49.         for (int i = 0; i < UnityEditorInternal.InternalEditorUtility.tags.Length; i++)
    50.         {
    51.             if (UnityEditorInternal.InternalEditorUtility.tags[i].Equals(tagToFollow))
    52.                 checkTag = true;
    53.         }
    54.         if (!checkTag)
    55.             Debug.LogWarning(tagToFollow + " tag not found in the project.");
    56. #endif
    57.  
    58.         guiGolor = Color.white;
    59.  
    60.         SetCameraSpecifications();
    61.  
    62.         UpdateTargets();
    63.     }
    64.    
    65.     void Update()
    66.     {      
    67.         //UpdateTargets();
    68.         for (int i = 0; i<targetsCount; i++)                                                        //You have to repeat it for every icons : be aware that if you have too much that could use a lot of ressoures
    69.         {
    70.             TargetStruct target = new TargetStruct();                                                //You have to create a temporary TargetStruct since you can't access a variable of an element in a list directly
    71.             target = TargetList[i];                                                                    //You take the item attached to the icon
    72.  
    73.             if (target.item)
    74.             {
    75.                 target.screenPos = camera.WorldToScreenPoint(target.item.transform.position);            //Convert world coordinates of the item into screen ones
    76.                 target.distance = Vector3.Distance(target.item.transform.position, transform.position);    //Get the distance between item and player
    77.             }
    78.            
    79.             if (target.distance > maxDistanceDisplay || target.distance < minDistanceDisplay)            //If the item is too far or too close
    80.             {
    81.                 target.xTargetSize = minTargetIconSize;                                                //you want it to disappear
    82.                 target.yTargetSize = minTargetIconSize;                                                //or at least to be in its smaller size
    83.             }
    84.             else
    85.             {
    86.                 target.xTargetSize = maxTargetIconSize / (target.distance);                            //Else you get its size with the
    87.                 target.yTargetSize = maxTargetIconSize / (target.distance);                            //distance : far<=>small / close<=>big
    88.             }
    89.        
    90.             if (target.distance>maxDistanceDisplay)                                                    //If the item is too far, you set its screen position : (this way it seems as if the icon was coming away from the screen to focus your target)
    91.             {
    92.                 if (target.screenPos.x < cameraXPos + cameraXSize * 0.5f)                            //-if it's under the center of the view field
    93.                     target.xTargetPos = cameraXPos;                                                        //to the bottom of the screen
    94.                 else                                                                                 //-else
    95.                     target.xTargetPos = cameraXPos + cameraXSize;                                        //to the top of the screen
    96.                
    97.                 if ((Screen.height - target.screenPos.y) < cameraYPos + cameraYSize * 0.5f)            //-if it's on the right of the view field
    98.                     target.yTargetPos = cameraYPos;                                                        //to the right of the screen
    99.                 else                                                                                 //-else
    100.                     target.yTargetPos = cameraYPos + cameraYSize;                                        //to the left of the screen
    101.             }
    102.             else                                                                                     //If the item is NOT too far, you set its screen position :
    103.             {
    104.                 target.xTargetPos = target.screenPos.x - target.xSize * 0.5f;                        //in x-axis to the item's x-position minus half of the icon's size
    105.                 target.yTargetPos = Screen.height - target.screenPos.y - target.ySize * 0.5f;        //in y-axis to the item's y-position minus half of the icon's size
    106.             }
    107.  
    108.             if (activateAlphaBlending)
    109.             {
    110.                 target.alpha = 1f;
    111.  
    112.                 if (target.xPos < cameraXPos + cameraXSize * alphaStartPercentage)
    113.                     target.alpha = Mathf.Clamp((target.xPos - cameraXPos) / (cameraXSize * alphaStartPercentage), 0f, 1f);
    114.                 else if (target.xPos + target.xSize > cameraXPos + cameraXSize * (1f - alphaStartPercentage))
    115.                     target.alpha = 1f - Mathf.Clamp((target.xPos + target.xSize - (cameraXPos + cameraXSize * (1f - alphaStartPercentage))) / (cameraXSize * alphaStartPercentage), 0f, 1f);
    116.  
    117.                 if (target.alpha == 1f)
    118.                 {
    119.                 if (target.yPos < cameraYPos + cameraYSize * alphaStartPercentage)
    120.                     target.alpha = Mathf.Clamp((target.yPos - cameraYPos) / (cameraYSize * alphaStartPercentage), 0f, 1f);
    121.                 else if (target.yPos + target.ySize > cameraYPos + cameraYSize * (1f - alphaStartPercentage))
    122.                     target.alpha = 1f - Mathf.Clamp(((target.yPos + target.ySize) - (cameraYPos + cameraYSize * (1f - alphaStartPercentage))) / (cameraYSize * alphaStartPercentage), 0f, 1f);
    123.                 }
    124.                 else
    125.                 {
    126.                     if (target.yPos < cameraYPos + cameraYSize * alphaStartPercentage)
    127.                         target.alpha -= 1f - Mathf.Clamp((target.yPos - cameraYPos) / (cameraYSize * alphaStartPercentage), 0f, 1f);
    128.                     else if (target.yPos + target.ySize > cameraYPos + cameraYSize * (1f - alphaStartPercentage))
    129.                         target.alpha -= Mathf.Clamp(((target.yPos + target.ySize) - (cameraYPos + cameraYSize * (1f - alphaStartPercentage))) / (cameraYSize * alphaStartPercentage), 0f, 1f);
    130.                 }
    131.             }
    132.            
    133.             target.xSize = Mathf.Lerp(target.xSize, target.xTargetSize, smoothGrowingParameter*Time.deltaTime);    //You do lerps on your icons size so you can adjust
    134.             target.ySize = Mathf.Lerp(target.xSize, target.yTargetSize, smoothGrowingParameter*Time.deltaTime);    //the speed of their resizing
    135.            
    136.             target.xPos = Mathf.Lerp(target.xPos, target.xTargetPos, smoothMovingParameter*Time.deltaTime);        //You do lerps on your icons position so you can adjust
    137.             target.yPos = Mathf.Lerp(target.yPos, target.yTargetPos, smoothMovingParameter*Time.deltaTime);        //their moving speed
    138.  
    139.             if (target.item)
    140.             {
    141.                 RaycastHit hitInfos = new RaycastHit();                                                                    //You create a new variable to stock the information of the coming raycast
    142.                 Physics.Raycast(transform.position, target.item.transform.position-transform.position, out hitInfos);    //and you RayCast from the player's position to the item's position
    143.                
    144.                 if(hitInfos.collider.gameObject.layer==8)                                                                //HERE IS A BIT TRICKY : you have to creat new layers (I called them "Interactive Items" and "Obstacles") and to apply them to your various items.
    145.                     target.directView=true;                                                                                //Then you select EVERY items in your scene and set their layer to "Ignore Raycast". After that you select your interactive items biggest shape (if you have big trigger colliders on them select the item that hold it),
    146.                 else                                                                                                     //and set their layers to "Interactive Items". Last part is setting every potential obstacle item layer to "Obstacles".
    147.                     target.directView=false;                                                                            //NOTE : Here my "Interactive Items" layer number is 8
    148.                
    149.                 TargetList[i] = target;                                                                    //You apply all the variables to your index-i icon in the ICONS LIST
    150.             }
    151.         }
    152.     }
    153.    
    154.     void OnGUI()
    155.     {
    156.         GUI.color = guiGolor;
    157.         for (int i = 0; i<targetsCount; i++)                                                                                        //For every icon
    158.         {
    159.             if (TargetList[i].screenPos.z>0 && (!directViewOnly || (directViewOnly && TargetList[i].directView)))                    //If the icon is in front of you and all the required conditions are okay
    160.             {
    161.                 if (activateAlphaBlending)
    162.                 {
    163.                     guiGolor.a = TargetList[i].alpha;
    164.                     GUI.color = guiGolor;
    165.                 }
    166.                 GUI.DrawTexture(new Rect(TargetList[i].xPos, TargetList[i].yPos, TargetList[i].xSize, TargetList[i].ySize), targetIcon);//you display the icon with it's size and position
    167.             }
    168.         }
    169.     }
    170.  
    171.     private void SetCameraSpecifications()
    172.     {
    173.         Rect cameraViewport =  this.camera.rect;
    174.         cameraXPos = cameraViewport.x * Screen.width;
    175.         cameraYPos = (1f - cameraViewport.y - cameraViewport.height) * Screen.height;
    176.         cameraXSize = cameraViewport.width * Screen.width;
    177.         cameraYSize = cameraViewport.height * Screen.height;
    178.     }
    179.  
    180.     public void UpdateTargets()
    181.     {
    182.         Targets = GameObject.FindGameObjectsWithTag(tagToFollow);            //Get all the potential targets in the scene (just replace it by your own tag : "MyTag")
    183.        
    184.         foreach (GameObject target in Targets)                                    //Put every detected GameObject into your ICONS LIST
    185.         {
    186.             TargetStruct newTarget = new TargetStruct();
    187.             newTarget.item = target;                                            //and attach each icon its GameObject
    188.             newTarget.alpha = 1f;
    189.             TargetList.Add(newTarget);
    190.         }
    191.        
    192.         targetsCount = TargetList.Count;                                        //Count the number of target in the scene
    193.     }
    194.  
    195.     public void DeleteTarget(GameObject obj, bool resetIconsPositions = false)        // 'obj' is the item tagged followed by the script
    196.     {                                                                                // 'resetIconsPositions' allow to reset the icons positions as if the script was just being started
    197.         for (int i = 0; i<targetsCount; i++)
    198.         {
    199.             TargetStruct target = new TargetStruct();
    200.             target = TargetList[i];
    201.             if (target.item.Equals(obj))
    202.             {
    203.                 TargetList.RemoveAt(i);
    204.                 obj.tag = "Untagged";
    205.                 targetsCount --;
    206.                 break;
    207.             }
    208.         }
    209.  
    210.         if (resetIconsPositions)
    211.             UpdateTargets();
    212.     }
    213. }
    214.  
    The DeleteTarget method can be called this way :
    Code (CSharp):
    1. if (Input.GetKeyUp(KeyCode.A))
    2.         {
    3.             GameObject.FindGameObjectWithTag("MainCamera").GetComponent<GUIRadarTest>().DeleteTarget(this.gameObject, false);
    4.             GameObject.FindGameObjectWithTag("Camera2").GetComponent<GUIRadarTest>().DeleteTarget(this.gameObject, false);
    5.             Destroy(this.transform.parent.gameObject);
    6.         }
    Note that if you have many cameras being able to "target" the object (each camera having its own script), you'll need to call the method for each of them.

    Here the download link of the updated test scene : http://we.tl/BAGiabf9ts

    Well enjoy it !
     
  7. MajorParts

    MajorParts

    Joined:
    Sep 27, 2014
    Posts:
    64
    Thanks for this! I had to start over with my project as I wanted multiplayer rather than mess about with AI and haven't got my scanners anymore yet, so haven't tried your changes.
    I did notice though, that this doesn't pick up multiplayer clients. Any thoughts on why that would be? The tags and layers are set up right still and things in the scene hierarchy get targeted still.

    I couldn't find this thread again at first and so googled....google came up with the script in a much larger form with a lot of the original stuff commented out....is that the latest work you've done on it, or an older version?

    Cheers,
    John
     
  8. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    Yes the script on the forum is the latest version : I also uploaded it on my personnal website so you may hav gotten on it ;)
    On the one hosted on my website there's also a part about the first test I did but which I finally abandonned :rolleyes:

    About the network thing, I can't figure anything : I never worked on it so I really have no idea what could cause the malfunction.
     
  9. MajorParts

    MajorParts

    Joined:
    Sep 27, 2014
    Posts:
    64
    ok, no worries. I'm using this as a start point for what I want to acheive and it's some way off yet :D
    Eventually, I want to be able to assign buttons to target specific things...next and previous enemy, same with friendly....target nearest craft targeting me....etc. I need to figure out how to apply yours to multiplayer clients first though.
    I shall plod on and see what I can learn!

    Cheers
     
  10. MajorParts

    MajorParts

    Joined:
    Sep 27, 2014
    Posts:
    64
    I've been looking into the network problem and I notice that "update targets" is only called in the "awake" function, so I presume clients are joining after the targets have been established. The only other call to update the targets is commented out. I removed the // from that line but things went weird with the display and controls.
    I thought that this was now updating the targets every frame and so obviously isn't good, so I added "if fire3" so it would only update if fire button 3 is pressed. It then didn't draw any targets so I commented it all out again.
    Now the weird stuff starts...I put 3 stationary objects in the scene and ran it in the editor as SP....3 targets as expected. When I ran it in the editor as MP...3 targets again. However, once I build and run the project, only 1 target out of the 3 is displayed. going back to the editor in SP and MP, still only 1 target of the 3.
    I duplicated the objects so there was now 5.....3 targets out of 5. I then duplicated the 5 and deleted the original 5....5 targets show up....build and run....back to 3 targets of 5

    I am so confused right now :D
     
  11. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    Hello everyone,
    Since I recently had some free time, I felt like updating this project :D

    It now works using Unity UI and doesn't rely anymore on old GUI: this implies far better performances and also more flexibility in scripting. This is why I decided to also improve it a bit ! ;)

    Now it features a custom editor for easy implementation and many new marker customisation (colors over distance, rotations, etc...)



    You can find the updated version on the script on its GitHub repository: https://github.com/Kardux/UIRadar
    If you want to try a WebGL demo of this, I uploaded one: http://www.roy-bodereau.fr/hudradar_demo_en.html


    Feel free to use it if you need it (only make sure to follow the CC-BY-SA license).

    Cheers
     
    khan-amil likes this.
  12. KarlLakner

    KarlLakner

    Joined:
    Jan 30, 2019
    Posts:
    13
    Hey,

    I found this through google, and even though it's outdated,I went ahead and implented it, v straightforward and did exactly what I wanted, for free as well :)

    However, I've run into a problem. I understand you're not updating the code anymore, but I wanted to see if you had time to explain the DeleteTarget() method? I can't get it to work, it just keeps returning errors...

    Thanks in advance!
     
  13. Kardux

    Kardux

    Joined:
    Apr 29, 2013
    Posts:
    8
    Hi,

    Not actively working on this script but still looking for ways to improve it and help other fellow programmers ;)

    My guess is the line causing error is the
    a_Target.tag = "Untagged";
    one. Which means the GameObject you are trying to remove from the targets list has already been destroyed: make sure to call the method before destroying the object.

    If the problem is different, feel free to post a snippet of your code calling the method and the error you have so I can check what's happening here !

    Anyway I'll probably take a look at the code and how I could update/upgrade it when coming back from vacation (1,5 week) since I didn't touch it for Over 2 years :rolleyes: Make sure to check it out on GitHub.

    Cheers,
     
    KarlLakner likes this.