Esempio n. 1
0
    void Update()
    {
        // did we press down our right mouse button and do we have units selected?
        if (Input.GetMouseButtonDown(1) && unitSelection.HasUnitsSelected())
        {
            // shoot a raycast from our mouse, to see what we hit
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            // cache the selected units in an array
            Unit[] selectedUnits = unitSelection.GetSelectedUnits();

            // shoot the raycast
            if (Physics.Raycast(ray, out hit, 100, layerMask))
            {
                unitSelection.RemoveNullUnitsFromSelection();

                // are we clicking on the ground?
                if (hit.collider.CompareTag("Ground"))
                {
                    UnitsMoveToPosition(hit.point, selectedUnits);
                    CreateSelectionMarker(hit.point, false);
                }

                // are we clicking on the resource?
                else if (hit.collider.CompareTag("Resource"))
                {
                    UnitsGatherResource(hit.collider.GetComponent <ResourceSource>(), selectedUnits);
                    CreateSelectionMarker(hit.collider.transform.position, true);
                }

                // did we click on an enemy?
                else if (hit.collider.CompareTag("Unit"))
                {
                    Unit enemy = hit.collider.gameObject.GetComponent <Unit>();

                    if (!Player.me.IsMyUnit(enemy))
                    {
                        UnitsAttackEnemy(enemy, selectedUnits);
                        CreateSelectionMarker(enemy.transform.position, false);
                    }
                }
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (Input.GetMouseButtonDown(1) && unitSelection.HasUnitsSelected())
        {
            Ray        ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            Unit[] selectedUnits = unitSelection.GetSelectedUnits();

            if (Physics.Raycast(ray, out hit, 1000, layerMask))
            {
                if (hit.collider.CompareTag("Ground"))
                {
                    unitSelection.RemoveNullUnitsFromSelection();
                    UnitsMoveToPosition(hit.point, selectedUnits);
                    CreateSelectionMarker(hit.point, false);
                }

                else if (hit.collider.CompareTag("Resource"))
                {
                    UnitsGatherResource(hit.collider.GetComponent <ResourceSource>(), selectedUnits);
                    CreateSelectionMarker(hit.point, true);
                }

                else if (hit.collider.CompareTag("Unit"))
                {
                    Unit enemy = hit.collider.gameObject.GetComponent <Unit>();
                    if (!Player.me.IsMyUnit(enemy))
                    {
                        UnitsAttackEnemy(enemy, selectedUnits);
                        CreateSelectionMarker(enemy.transform.position, false);
                    }
                }
            }
        }
    }