//Find the closest, empty and safe cover void TakeCover() { float[] coverDistance = new float[cover.Length]; for (int i = 0; i < cover.Length; i++) { coverDistance[i] = Vector3.Distance(this.transform.position, cover[i].transform.position); } float[] sortedDistance = (float[])coverDistance.Clone(); System.Array.Sort(sortedDistance); for (int i = 0; i < cover.Length; i++) { int j = System.Array.IndexOf(coverDistance, sortedDistance[i]); CoverScript coverscript = cover[j].GetComponent <CoverScript>(); if (coverscript.safe && !coverscript.full) { coverNum = j; break; } } }
// Start is called before the first frame void Start() { rb = GetComponent <Rigidbody2D>(); cc = GetComponent <CoverScript>(); }