Example #1
0
    private void Grow()
    {
        if (growthStage < growthStages.Length)
        {
            transform.localPosition = growthStages[growthStage].localposition;
            SetGlobalScale(transform, growthStages[growthStage].localScale);

            if (growthSound != null)
            {
                audioSource.pitch = growthStages[growthStage].pitch;
                audioSource.PlayOneShot(growthSound);
            }

            growthStage++;

            Invoke("Grow", growthTime);
        }
        else
        {
            Unit unit = Instantiate(unitPrefab, new Vector3(transform.position.x, 0.0f, transform.position.z), transform.rotation);
            unit.Activate(Team);

            Destroy(gameObject);
        }
    }
Example #2
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0) && Input.mousePosition.y >= 50)
        {
            startMousePos = Input.mousePosition;
            startPos      = Camera.main.ScreenToWorldPoint(new Vector3(startMousePos.x, startMousePos.y, -Camera.main.transform.position.z)); //FIX

            selectRect.SetActive(true);
        }
        if (Input.GetMouseButtonUp(0) && Input.mousePosition.y >= 50)
        {
            Vector2 pos    = Input.mousePosition;
            Vector2 endPos = Camera.main.ScreenToWorldPoint(new Vector3(pos.x, pos.y, -Camera.main.transform.position.z));

            selectRect.SetActive(false);

            UpdateSelected(startPos, endPos);
        }

        // Draw select rectangle
        if (selectRect.active)
        {
            RectTransform rt = selectRect.GetComponent <RectTransform>();
            rt.localPosition = new Vector3(Mathf.Min(startMousePos.x, Input.mousePosition.x) - canvasWidth / 2,
                                           Mathf.Min(startMousePos.y, Input.mousePosition.y) - canvasHeight / 2, 0);
            rt.sizeDelta = new Vector2(Mathf.Abs(startMousePos.x - Input.mousePosition.x),
                                       Mathf.Abs(startMousePos.y - Input.mousePosition.y));
        }

        if (Input.GetMouseButtonDown(1))
        {
            var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            ActivateableBehaviour activateable = null;
            //if(Input.GetKey(KeyCode.LeftControl)) {
            RaycastHit2D rayHit2D = Physics2D.Raycast(
                ray.origin,
                ray.direction,
                Mathf.Infinity,
                LayerMask.GetMask("Activateable")
                );
            Collider2D collider = rayHit2D.collider;
            if (collider != null)
            {
                activateable = collider.gameObject.GetComponent <ActivateableBehaviour>();
            }
            //}
            RaycastHit rayCastHit = new RaycastHit();
            if (Physics.Raycast(ray.origin, ray.direction, out rayCastHit))
            {
                foreach (GameObject unitObject in selected)
                {
                    Unit unit = unitObject.GetComponent <Unit>();
                    unit.Pathfind(rayCastHit.point);
                    unit.Activate(activateable);
                }
            }
        }
    }
    void NextTurn(List <Unit> army)
    {
        GetFirstNotUsedUnit(army);

        if (activeUnit == null)
        {
            NewTurn(army);
        }

        if (activeUnit.isAlive())
        {
            activeUnit.Activate();
            map.ShowRange(activeUnit.position);
        }
    }
Example #4
0
    public void Trigger(Unit triggerer)
    {
        if (_triggered)
        {
            return;
        }

        if (triggerer != null)
        {
            MDebug.Log("^ai OnTrigger " + triggerer.name);
            m_unit.GetComponent <UnitRotationController>().TurnToPosition(triggerer.transform);
            SetPreferredTarget(triggerer);
        }

        m_unit.Activate();

        m_unit.Identify(triggerer);

        _triggered = true;
        TriggerUnitsForGroup(this, triggerer);
    }
Example #5
0
        IEnumerator Step()
        {
            Debug.Log($"Start step team {currentTeam}");


            yield return(new WaitUntil(() => {
                Unit unit = GetUnitMouse(currentTeam, UnitFindFlag.With);
                if (!unit)
                {
                    return false;
                }
                if (unit.team == currentTeam)
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        currentUnit = unit;
                        Debug.Log(currentUnit.name);
                        return true;
                    }
                }
                return false;
            }));

            currentUnit.Activate();
            battleHUD.SetUnit(currentUnit);
            yield return(new WaitUntil(() => {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    currentUnit.Disactive();
                    battleHUD.ResetUnit();
                    StopCoroutine(Step());
                    StartCoroutine(Step());
                }
                return currentUnit.isActionStep;
            }));
        }