private void FixedUpdate() { // Rotate rb2d.MoveRotation(rotation - 90); // Unshrink if necessary if (shouldMaximize) { shouldMaximize = !Maximize(); } // Set Target if (Input.GetMouseButtonDown(1) && isFullscale()) { StopAutomatic(); Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero); if (hit.collider != null) { targetObject = hit.collider.gameObject.GetComponent <LandableObject>(); landing = true; SetLandingTargetText(hit.collider.gameObject); } } // Move with the planet if landed if (landed) { MoveTowards(); } }
public void Enable(GameObject ship, LandableObject world) { theShip = ship.GetComponent <Ship>(); theWorld = world; title.text = world.name.ToUpper(); panelCargo.text = stringCargo + theShip.currentCargo + "/" + theShip.cargoSize; panelPlanetResources.text = stringPlanet + theWorld.resources; }
public LandableObject FindClosestLandableObject() { landables = starSystem.GetLandables(); if (landables.Length > 0) { LandableObject closest = landables[0]; float dist = Vector2.Distance(transform.position, closest.transform.position); foreach (LandableObject obj in landables) { if (Vector2.Distance(transform.position, obj.transform.position) < dist) { closest = obj; dist = Vector2.Distance(transform.position, obj.transform.position); } } return(closest); } return(null); }
public void Land(GameObject ship, LandableObject target) { closeAll(); worldMenu.SetActive(true); worldMenu.GetComponent <LandableMenu>().Enable(ship, target); }
public void notifyOfLand(GameObject ship, LandableObject target) { hudManager.Land(ship, target); }
/*public bool Land(LandableObject target) * { * //------Stopping * if (!stoppedFirst && !StopLook(target.transform)) * return false; * else * stoppedFirst = true; * //-------------------------- * * if (!distanceToStop && !ThrustToTarget(target.transform)) * return false; * else * distanceToStop = true; * * //--------Stopping at target * if (!Stop() && !stoppedAtTarget) * return false; * else * { * stoppedAtTarget = true; * thrusting = false; * } * * //-------Aligning with Target and shrink * bool moved = MoveTowards(target.transform); * bool shrunk = Shrink(); * * if (!moved || !shrunk) * return false; * else // -------------------------------FINISHED * { * // reset landing bools * landing = false; * stoppedFirst = false; * landingTargetTargeted = false; * distanceToStop = false; * thrustingForLand = false; * stoppedAtTarget = false; * * // the eagle has landed * landed = true; * * if (playerController != null) * playerController.notifyOfLand(gameObject, target); * // * // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OPEN WORLD MENU * // * return true; * } * }*/ public bool Land(LandableObject target) { //------Stopping if (!stoppedFirst && !Stop()) { return(false); } else { stoppedFirst = true; } //-------------------------- //-------Turning if (!landingTargetTargeted && !LookAt(target.transform)) { return(false); } else { landingTargetTargeted = true; } //--------------------------- //-------Thrusting to Target if (!distanceToStop && !ThrustToTarget(target.transform)) { return(false); } else { distanceToStop = true; } //---------------------------- //-------Aligning with Target if (!distanceToStop && !ThrustToTarget(target.transform)) { return(false); } else { distanceToStop = true; } //---------------------------- //--------Stopping at target if (!Stop() && !stoppedAtTarget) { return(false); } else { stoppedAtTarget = true; thrusting = false; } //-------Aligning with Target and shrink bool moved = MoveTowards(target.transform); bool shrunk = Shrink(); if (!moved || !shrunk) { return(false); } else // -------------------------------FINISHED { // reset landing bools landing = false; stoppedFirst = false; landingTargetTargeted = false; distanceToStop = false; thrustingForLand = false; stoppedAtTarget = false; // the eagle has landed landed = true; if (playerController != null) { playerController.notifyOfLand(gameObject, target); } // // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% OPEN WORLD MENU // return(true); } }
public bool Manual() { if (inHyperSpace) { return(false); } bool ret = false; // Accelerate if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { thrusting = true; ret = true; } // Stop if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { Stop(); ret = true; } // Turn right if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { rotation -= rotSpeed * Time.deltaTime; ret = true; } // Turn left if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { rotation += rotSpeed * Time.deltaTime; ret = true; } // Land if (Input.GetKey(KeyCode.L)) { targetObject = FindClosestLandableObject(); SetLandingTargetText(targetObject.gameObject); landing = true; } if (Input.GetKey(KeyCode.T)) { TakeOff(); } if (Input.GetKey(KeyCode.U)) { //script.shouldExecute = true; } else if (ret || Input.GetKey(KeyCode.I)) { //script.shouldExecute = false; ret = true; } if (Input.GetKey(KeyCode.K)) { //currentDirections = map.getStackTo(starSystem, targetStar); } if (!(currentDirections == null || currentDirections.Count == 0) && (jumping || Input.GetKey(KeyCode.J))) { jumping = true; } if (Input.GetKey(KeyCode.M)) { playerController.toggleMap(); } Thrust(); return(ret); }