void FindLockableTargets() { Collider[] cols = Physics.OverlapSphere(states.value.mTransform.position, 10); Vector3 camDir = cameraTransform.value.forward; camDir.y = 0; for (int i = 0; i < cols.Length; i++) { ILockable l = cols[i].GetComponentInChildren <ILockable>(); if (l == null) { continue; } float dot = Vector3.Dot(camDir, cols[i].transform.position); if (dot > 0) { Transform t = l.LockOn(); if (t != null) { if (!targets.Contains(t)) { targets.Add(l.LockOn()); } } } } float minDist = 100; for (int i = 0; i < targets.Count; i++) { float tempDist = Vector3.Distance(states.value.mTransform.position, targets[i].position); if (tempDist < minDist && targets[i] != states.value.currentTarget) { minDist = tempDist; states.value.currentTarget = targets[i]; } } }
private void FindLockableTargets() { Collider[] colliders = Physics.OverlapSphere(states.mTransform.position, 10); Vector3 cameraDirection = cameraTransform.value.forward; cameraDirection.y = 0; for (int i = 0; i < colliders.Length; i++) { ILockable lockableTarget = colliders[i].GetComponent <ILockable>(); if (lockableTarget == null) { continue; } float dot = Vector3.Dot(cameraDirection, colliders[i].transform.position - cameraTransform.value.position); if (dot > 0) { Transform t = lockableTarget.LockOn(); if (t != null) { if (!targets.Contains(t)) { targets.Add(t); } } } } float minDistance = 100; for (int i = 0; i < targets.Count; i++) { float tempDistance = Vector3.Distance(states.mTransform.position, targets[i].position); if (tempDistance < minDistance && targets[i] != states.currentLockonTarget) { minDistance = tempDistance; states.currentLockonTarget = targets[i]; } } }