private void DetectAndShowItems() { var colliders = Physics.OverlapSphere(transform.position, radius, itemsLayerMask); for (var i = 0; i < colliders.Length; i++) { var collider = colliders[i]; if (!PhysicsExtensions.IsColliderInSight(transform.position, collider, ~ignoreOnSightTest)) { continue; } var diffVector = collider.transform.position - transform.position; var itemPosition = transform.position + (diffVector * scale); var itemComponent = (Item)collider.GetComponent <Item>(); if (itemComponent == null) { throw new Exception("Item component not found on object."); } var item = PoolManager.instance.Spawn <RadarItemRepresentation>(transform, itemPosition, collider.transform.rotation); item.SetColor(itemComponent.colorOnRadar); Items.Add(item); } }
private void DetectAndShowEnemies() { var colliders = Physics.OverlapSphere(transform.position, radius, enemyLayerMask); for (var i = 0; i < colliders.Length; i++) { var collider = colliders[i]; if (!PhysicsExtensions.IsColliderInSight(transform.position, collider, ~ignoreOnSightTest)) { continue; } var diffVector = collider.transform.position - transform.position; var enemyPosition = transform.position + (diffVector * scale); var enemy = PoolManager.instance.Spawn <RadarEnemyShipRepresentation>(transform, enemyPosition, collider.transform.rotation); Enemies.Add(enemy); } }
private void UpdateLockingSystem() { if (lockingSystemOn) { var screenCenter = ((RectTransform)lockCrosshair.canvas.transform).sizeDelta / 2f; var LockAreaLimitHelperPos = RectTransformUtility.WorldToScreenPoint(lockingSystemCamera, ((RectTransform)LockAreaLimitHelper.transform).position); var lockAreaRadius = Vector2.Distance(screenCenter, LockAreaLimitHelperPos); if (targetBeingLocked != null) { if (Vector2.Distance(RectTransformUtility.WorldToScreenPoint(lockingSystemCamera, targetBeingLocked.transform.position), screenCenter) > lockAreaRadius) { targetBeingLocked = null; leftGuidedMissileCannon.target = null; rightGuidedMissileCannon.target = null; lockCrosshair.enabled = false; } else if (Time.time - targetBeingLockedStartTime > timeToLockTarget) { lockCrosshair.color = lockCrosshairLockedColor; leftGuidedMissileCannon.target = targetBeingLocked.transform; rightGuidedMissileCannon.target = targetBeingLocked.transform; } } if (targetBeingLocked == null) { var allEnemies = GameObject.FindObjectsOfType <EnemyShipControllerV2>(); float selectedEnemySqrMagnitude = float.MaxValue; foreach (var enemy in allEnemies) { var collider = enemy.GetComponent <Collider>(); if (collider == null) { continue; } if (PhysicsExtensions.IsColliderInSight(targetDetectorOrigin.position, collider, ~targetDetectionLayersToIgnore)) { var enemyScreenPoint = RectTransformUtility.WorldToScreenPoint(lockingSystemCamera, enemy.transform.position); if (Vector2.Distance(enemyScreenPoint, screenCenter) > lockAreaRadius) { continue; } var currSqrMagnitude = (targetDetectorOrigin.position - collider.transform.position).sqrMagnitude; if (currSqrMagnitude < selectedEnemySqrMagnitude) { selectedEnemySqrMagnitude = currSqrMagnitude; targetBeingLocked = enemy; targetBeingLockedStartTime = Time.time; lockCrosshair.enabled = true; lockCrosshair.color = lockCrosshairUnlockedColor; ((RectTransform)lockCrosshair.transform).localScale = new Vector3(.15f, .15f, .15f); ((RectTransform)lockCrosshair.transform).DOScale(new Vector3(.04f, .04f, .04f), timeToLockTarget); lockCrosshair.color = lockCrosshairUnlockedColor.Copy(0); lockCrosshair.DOFade(1f, timeToLockTarget); } } } } if (targetBeingLocked != null) { Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(lockingSystemCamera, targetBeingLocked.transform.position); ((RectTransform)lockCrosshair.transform).anchoredPosition = screenPoint - ((RectTransform)lockCrosshair.canvas.transform).sizeDelta / 2f; } else { lockCrosshair.enabled = false; } } }