title: How to identify multiple objects in a sphere cast?
body: <p>I am trying to implement a RADAR sensor in unity. I am currently using sphere cast to identify the object and measure its velocity and distance. At the moment even though there are several objects in within the radius of the sphere cast ,It only identifies the nearest one. How can i make it recognize all the objects within the sphere cast.?</p>
  
  <p>Any help would be appreciated..
  This is what i have done now which just identifies identify the closest object.</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class spherecast : MonoBehaviour
  {
  
      Rigidbody rb;
  
  
      public GameObject curobject;
  
      public float radius;
      public float maxdist;
      public LayerMask layermask;
      public float velocity;
      public Time deltatime;
      public Vector3 previous;
  
      private Vector3 origin;
      private Vector3 direction;
  
      private float hitdist;
      // Use this for initialization
      void Start()
      {
          previous = curobject.transform.position;
      }
  
      // Update is called once per frame
      void Update()
      {
          velocity = hitdist/Time.deltaTime;
          origin = transform.position;
          direction = transform.forward;
          RaycastHit hit;
          if (Physics.SphereCast(origin, radius, direction, out hit, maxdist, layermask, QueryTriggerInteraction.UseGlobal))
          {
              curobject = hit.transform.gameObject;
              hitdist = hit.distance;
              Debug.Log("Distance" + hitdist);
              velocity = ((curobject.transform.position - previous).magnitude) / Time.deltaTime;
              previous = curobject.transform.position;
              Debug.Log("Velocity" + velocity);
             // Debug.Log("Velocity = " + velocity);
          }
          else
          {
              hitdist = maxdist;
              curobject = null;
          }
      }
      private void ondrawgizmosselected()
      {
  
          Gizmos.color = Color.red;
          Debug.DrawLine(origin, origin + direction * hitdist);
          Gizmos.DrawWireSphere(origin + direction * hitdist, radius);
      }
  }
  </code></pre>