Exemple #1
0
    /**
     * Called on each game loop
     * We use it to detect mouse clicks when moving a
     */
    void Update()
    {
        // Detect left clicks only on planets
        if (Input.GetMouseButtonDown(0) && inTransferingFleetMouseState())
        {
            RaycastHit hit = findObjectsOnScreen(); //Will return Vector3(0,0,0) if nothing found
            if (!(hit.point.x == 0 &&
                  hit.point.y == 0 &&
                  hit.point.z == 0))
            {
                //If we hit a planet, we send the fleet there
                GameObject hitObject = hit.transform.gameObject;
                if (hitObject.tag == "Planet" && currentlySelectedPlanet != null)
                {
                    // Take the fleet at the currently selected planet, and move it to this planet
                    ShipDisplay      shipScript  = shipDisplay.GetComponent <ShipDisplay>();
                    GameObject       chosenFleet = shipScript.getChosenFleet();
                    MoveShipsCommand moveShips;
                    if (chosenFleet != null)
                    {
                        shipScript.clearChosenFleet();

                        moveShips = new MoveShipsCommand(
                            chosenFleet,
                            currentlySelectedPlanet,
                            hitObject,
                            CurrentPlayer.instance().getCurrentPlayerGameObject()
                            );
                    }
                    else
                    {
                        // TODO - Figure out how to handle selecting which fleet to go
                        GameObject currentFleet = currentlySelectedPlanet.GetComponent <Planet>().getFleetOverPlanet();
                        moveShips = new MoveShipsCommand(
                            currentFleet,
                            currentlySelectedPlanet,
                            hitObject,
                            CurrentPlayer.instance().getCurrentPlayerGameObject()
                            );
                    }
                    Player p = CurrentPlayer.instance().getCurrentPlayer();
                    p.addCommand(moveShips);
                    hitObject.GetComponent <Planet>().setTransferingFleet(true); // Don't show the player menu
                }
            }

            // Deactivate the moving fleet cursor regardless if we find something
            deactiveTargetMouse();
        }
        else if (Input.GetMouseButtonDown(1) && inTransferingFleetMouseState())
        {
            // Cancel moving the fleet if a right click is detected
            deactiveTargetMouse();
        }
    }