// Function that locks on the closest enemy available. If there are no enemies available, just center the camera. void LockEnemy() { if (m_LockableEnemies.Count != 0) { float closestDistance = float.MaxValue; float enemyDistance; foreach (Transform enemy in m_LockableEnemies) { enemyDistance = Vector3.Distance(m_PlayerTransform.position, enemy.position); if (closestDistance > enemyDistance) { if (!Physics.Raycast(enemy.position, m_PlayerTransform.position - enemy.position, Vector3.Distance(GlobalData.PlayerTransform.position, enemy.position), (1 << LayerMask.NameToLayer("Environment")))) { closestDistance = enemyDistance; GlobalData.LockedEnemyTransform = enemy; } } } if (GlobalData.LockedEnemyTransform != null) { GlobalData.IsEnemyLocked = true; } else { GlobalData.CenterCamera(); } } else { GlobalData.CenterCamera(); } }