Example #1
0
    /// ==============================================
    public void SetDestination(Vector3 worldPos)
    {
        var positionToCheck = worldPos;

        int i = 0;

        while (this.IsTargetOccupied(positionToCheck) && i < 100)
        {
            positionToCheck = worldPos + Walk.GetPhyllotaxisOffsetByIndex(i, this.agent.radius * 4);
            i++;
        }

        this.targetPosition = positionToCheck;
        this.SetDestinationFlag(positionToCheck);
        this.agent.SetDestination(this.targetPosition);
    }
Example #2
0
    /// ==============================================
    /// <summary>
    ///
    /// </summary>
    public void UnitCommandRutine()
    {
        if (this.status != PUMStatus.IDLE && this.status != PUMStatus.COMMAND)
        {
            return;
        }

        if (this.selectedUnits.Count == 0)
        {
            return;
        }

        // Empezamos a comandar
        if (Input.GetMouseButtonDown(1))
        {
            this.status = PUMStatus.COMMAND;

            Ray   ray = sceneCamera.ScreenPointToRay(Input.mousePosition);
            float distance;
            groundPlane.Raycast(ray, out distance);

            this.commandPosition = ray.GetPoint(distance);

            var go = Instantiate(this.commandMarkerPrfb, this.commandPosition, Quaternion.identity);

            this.marker = go.GetComponent <CommandMarker>();
        }

        if (this.status == PUMStatus.COMMAND)
        {
            if (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0)
            {
                Ray   ray = sceneCamera.ScreenPointToRay(Input.mousePosition);
                float distance;
                groundPlane.Raycast(ray, out distance);

                Vector3 point = ray.GetPoint(distance);

                this.marker.RotateTo((point - this.commandPosition).normalized);
                this.commandRotation = this.marker.transform.rotation;
            }
        }

        // Terminamos de comandar
        if (Input.GetMouseButtonUp(1))
        {
            this.status = PUMStatus.IDLE;

            float index = 0;

            foreach (Unit u in this.selectedUnits)
            {
                Vector3 offset = Walk.GetPhyllotaxisOffsetByIndex(index, 2);

                u.ExecuteOrder(this.commandPosition + offset, this.commandRotation);

                index++;
            }

            this.marker.End();
        }
    }