Ejemplo n.º 1
0
    public void SendUnits(GameObject targetPlanet, GameObject planetOwner)
    {
        int unitsToRelease = (data.GetNumberOfUnits() / 2);

        data.ReleaseUnits(unitsToRelease);
        TravellingUnit units = Instantiate(travellingUnitsPrefab, this.gameObject.transform.position, Quaternion.identity).GetComponent <TravellingUnit>();

        units.Initialize(unitsToRelease, data.GetOwner(), targetPlanet, 20.0f * (1 + planetOwner.GetComponent <PlayerData>().UnitSpeedModifier));
    }
Ejemplo n.º 2
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            return;
        }
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit2D[] hits = Physics2D.RaycastAll(playerCamera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
            foreach (RaycastHit2D hit in hits)
            {
                if (hit.collider)
                {
                    GameObject clickedObject = hit.transform.gameObject;
                    if (clickedObject.tag == "planet")
                    {
                        Debug.Log("Clicked on " + clickedObject.name);
                        PlanetData planet = clickedObject.GetComponent <PlanetData>();
                        if (planet.GetOwner() == this.gameObject)
                        {
                            isPlanetActive = true;
                            activePlanet   = clickedObject;
                        }
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (isPlanetActive)
            {
                RaycastHit2D[] hits = Physics2D.RaycastAll(playerCamera.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
                foreach (RaycastHit2D hit in hits)
                {
                    if (hit.collider)
                    {
                        GameObject releaseObject = hit.transform.gameObject;
                        if (releaseObject.tag == "planet")
                        {
                            PlanetData planet = releaseObject.GetComponent <PlanetData>();
                            if (releaseObject != activePlanet)
                            {
                                //planetUnits.SendUnits(releaseObject, gameObject);
                                CmdSendUnits(gameObject, activePlanet, releaseObject);
                            }
                        }
                    }
                }
            }
            isPlanetActive = false;
        }
    }