ITargetable FindClosestToExitTarget() { ITargetable bestTarget = null; int biggestPathIndex = -1; float closestDistToWaypoint = float.MaxValue; for (int i = 0; i < targetsCount; i++) { ITargetable possibleTarget = _targetsBuffer[i].GetComponent <ITargetable>(); if (possibleTarget != null && !possibleTarget.IsDied) { MoveByPath mbp = possibleTarget.GameObj.GetComponent <MoveByPath>(); if (mbp.PathIndex > biggestPathIndex) { bestTarget = possibleTarget; biggestPathIndex = mbp.PathIndex; closestDistToWaypoint = (mbp.WaypointPoint - possibleTarget.Position).magnitude; } else if (mbp.PathIndex == biggestPathIndex) { float distToWaypoint = (mbp.WaypointPoint - possibleTarget.Position).magnitude; if (distToWaypoint < closestDistToWaypoint) { bestTarget = possibleTarget; closestDistToWaypoint = distToWaypoint; } } } } return(bestTarget); }
protected override void Awake() { base.Awake(); _collider = GetComponent <Collider2D>(); moveByTransform = GetComponentInParent <MoveByTransform>(); moveByPath = GetComponentInParent <MoveByPath>(); }
protected override void Awake() { base.Awake(); _attachments = GetComponent <AttachmentPoints>(); _attachments.Points.TryGetValue("Foot", out footPoint); weapon = GetComponentInChildren <Weapon>(); moveByPath = GetComponent <MoveByPath>(); }
void ProvidePath(MoveByPath move, string pathName) { for (int i = 0; i < Curves.Count; i++) { if (Curves[i].gameObject.name == pathName) { move.AssignPath(Curves[i]); } } }
void SpawnMob(GameObject mobPrefab, string pathName) { var path = paths.Find(e => e.gameObject.name == pathName); Mob mob = SimplePool.Spawn(mobPrefab, path.FirstSegment, transform.rotation).GetComponent <Mob>(); // mob.transform.position += new Vector3(i % 2 == 0 ? WaveControl.RangeBetweenMobsInGroup.x*i : 0, // i % 2 == 0 ? WaveControl.RangeBetweenMobsInGroup.y*i : 0, 0); MoveByPath mbp = mob.GetComponent <MoveByPath>(); mbp.SetPath(pathName); MobSpawnedEvent?.Invoke(mob, this); }