private Action FuncAttackNearestEnemy() { return(() => { GameObject nearestEnemy = null; float nearestDistance = float.MaxValue; foreach (GameObject enemy in EnemyManager.Enemies) { float distance = Vector3.Distance(enemy.transform.position, robot.gameObject.transform.position); if (distance < nearestDistance) { nearestEnemy = enemy; nearestDistance = distance; } } if (nearestEnemy != null && nearestDistance < 80.0f) { var direction = Vector3.Normalize(nearestEnemy.transform.position - robot.transform.position); if (Vector3.Dot(direction, robot.transform.forward) > 0) { robot.Attack(nearestEnemy); } } }); }
public void Update() { if (Input.GetKey(KeyCode.W)) { robotSphere.Move(Movable.Move.Front, 1); } if (Input.GetKey(KeyCode.S)) { robotSphere.Move(Movable.Move.Back, 1); } if (Input.GetKey(KeyCode.A)) { robotSphere.Move(Movable.Move.Left, 5); } if (Input.GetKey(KeyCode.D)) { robotSphere.Move(Movable.Move.Right, 5); } if (Input.GetMouseButton(1)) { if (CameraManager.CurrentActiveCamera.name.StartsWith("Robot POV")) { if (Time.time - lastshot > 0.15f) { lastshot = Time.time; Ray ray = CameraManager.CurrentActiveCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hitInfo)) { if (hitInfo.collider.gameObject.name.StartsWith("AlienBeetle")) { robotSphere.Attack(hitInfo.collider.gameObject); } else { robotSphere.Attack(hitInfo.point); } } } } } }