private IEnumerator FindClosestObject() { while (true) { var CurrentBearFloor = GameplayStatics.GetCurrentFloorOfObject(this.gameObject); if (AttackObject != null) { //clears out the attack object if it's too far away if (Vector3.Distance(transform.position, AttackObject.gameObject.transform.position) > maxDistToObject) { AttackObject.ClearHighlight(); AttackObject = null; } } var destructableEnumerator = GameObject.FindObjectsOfType <InteractableObject>() .Where(obj => !obj.bIsDestroyed); foreach (var item in destructableEnumerator) { if (CurrentBearFloor != GameplayStatics.GetCurrentFloorOfObject(item.gameObject)) { continue; } var newObjPos = Vector3.Distance(transform.position, item.gameObject.transform.position); if (newObjPos < maxDistToObject) { if (AttackObject != null) { var attackObjPos = Vector3.Distance(transform.position, AttackObject.gameObject.transform.position); if (newObjPos > attackObjPos) { AttackObject.ClearHighlight(); AttackObject = item; } } else { AttackObject = item; } } } if (AttackObject != null) { AttackObject.SetHighlight(); } //Sleep for a bit and do this all again yield return(new WaitForSeconds(asyncLookupThreadSleep)); } yield return(null); }
protected IEnumerator CombustionTimer() { this.CombustionLatch = true; yield return(new WaitForSeconds(CombustionIncrement)); this.CombustionCounter++; this.CombustionLatch = false; if (CombustionCounter >= CombustionThreshold) { this.CombustionCounter = 0; float fireYSpawnPos = GameplayStatics.FloorYPositionLookup[GameplayStatics.GetCurrentFloorOfObject(this.gameObject)] + 0.25f; Instantiate(Resources.Load <GameObject>("FireObject"), new Vector3(transform.position.x, fireYSpawnPos, transform.position.z - (GameplayStatics.FIRE_SPAWN_Z)), Quaternion.identity); } }