public float getDensity() { if (hideFlags == HideFlags.HideInHierarchy) { return(-1); } int nearbys = 0; float radius = 2.0f; foreach (GameObject p in pl.pedestrians) { if (p != this && Vector3.Distance(transform.position, p.transform.position) < radius && p.hideFlags != HideFlags.HideInHierarchy) { nearbys++; } } float density = nearbys / (radius * radius * Mathf.PI); it.updateDensity(density); return(density); }