public static List <GameObject> anyTagsInRange(Vector3 fromHere, float withinRadius, eNavTargets anyOfThese, bool getList) { string thisTag = anyOfThese.ToString(); List <GameObject> goList = new List <GameObject>(); foreach (Collider c in Physics.OverlapSphere(fromHere, withinRadius)) { if (c.tag == thisTag) { goList.Add(c.gameObject); } } // nope, went through entire list of possible colliders, // and nothing was what was looked for. return(goList); }
// look for a SPECIFIC SINGLE nav target. public static GameObject getRandomNavTarget(eNavTargets tagName) { GameObject[] targets = GameObject.FindGameObjectsWithTag(tagName.ToString()); // if there was not anything, can't return an indexed object of something doesn't exist if (targets.Length == 0) { return((GameObject)null); } // if we DO have targets, see if any are commonAI and are "infected". // if so, don't consider them from either side attraction/attack. for (int i = targets.Length - 1; i >= 0; i--) { commonAI o = targets[i].GetComponent <commonAI>(); if (o != null && o.IsInfected) { targets[i] = (GameObject)null; } } // Yup, we have something, get a random instance from one available return(targets [Random.Range(0, targets.Length)]); }
// don't allow the "commonAI" to update this attack object list directly public void AddAttackTarget(eNavTargets newTarget) { // store the STRING tag version we expect the objects to have // for use of comparing the "tag" property of collision objects found canAttackThese.Add(newTarget.ToString()); }