private bool CheckIfInRange(out Vector3 targetPos) { targetPos = Vector3.zero; Collider2D circleHit = Physics2D.OverlapCircle(transform.position, range, playerMask_); if (circleHit == null) { return(false); } Transform target = circleHit.transform; Vector3 dirToTarget = (target.position - transform.position).normalized; if (Vector3.Angle(MyUtility.DirFromAngle(angleTop), dirToTarget) < Vector3.Angle(MyUtility.DirFromAngle(angleTop), MyUtility.DirFromAngle(angleBottom)) && Vector3.Angle(MyUtility.DirFromAngle(angleBottom), dirToTarget) < Vector3.Angle(MyUtility.DirFromAngle(angleBottom), MyUtility.DirFromAngle(angleTop))) { var dir = (target.position - bulletSpawnTransform_.position).normalized; var hit = Physics2D.Raycast(bulletSpawnTransform_.position, dir, range, raycastMask_); if (hit.transform.tag == "Player") { targetPos = target.position; return(true); } } return(false); }
private void OnDrawGizmos() { Gizmos.color = Color.cyan; if (showArc) { Gizmos.DrawLine(transform.position, MyUtility.DirFromAngle(surfaceArc / 2) + transform.position); Gizmos.DrawLine(transform.position, MyUtility.DirFromAngle(-surfaceArc / 2) + transform.position); } }
private void OnDrawGizmos() { if (showAngle) { Gizmos.color = Color.red; Gizmos.DrawLine(transform.position, (MyUtility.DirFromAngle(angleTop) * range) + transform.position); Gizmos.color = Color.green; Gizmos.DrawLine(transform.position, (MyUtility.DirFromAngle(angleBottom) * range) + transform.position); } }
private bool IsCursorInAngle(Vector2 cursorPos, float startAngle, float endAngle) { var dirToCursor = (cursor_.position - transform.position).normalized; if (Vector3.Angle(MyUtility.DirFromAngle(startAngle), dirToCursor) < Vector3.Angle(MyUtility.DirFromAngle(startAngle), MyUtility.DirFromAngle(endAngle)) && Vector3.Angle(MyUtility.DirFromAngle(endAngle), dirToCursor) < Vector3.Angle(MyUtility.DirFromAngle(endAngle), MyUtility.DirFromAngle(startAngle))) { return(true); } return(false); }