IEnumerator RunSequence()
    {
        mCanvas.SetActive(false);
        mCanvas.SetActive(false);
        while (CheckMoving())
        {
            yield return(null);
        }
        mCanvas.SetActive(true);
        mInMotion = false;
        mCamera.StartGameplayCamera();
        GameObject.Find("Enemies").GetComponent <EnemyController>().BuildMovement();

        // Fix hitboxes for player clicks
        foreach (GameObject FriendlyUnit in mFriendlyUnits)
        {
            if (FriendlyUnit != null)
            {
                FriendlyUnit.GetComponent <BoxCollider2D>().size  = new Vector2(.95f, .95f);
                FriendlyUnit.GetComponent <Movement>().mMoveCount = 0;
            }
        }

        foreach (GameObject EnemyUnit in mEnemyUnits)
        {
            if (EnemyUnit != null)
            {
                EnemyUnit.GetComponent <BoxCollider2D>().size  = new Vector2(.95f, .95f);
                EnemyUnit.GetComponent <Movement>().mMoveCount = 0;
            }
        }
    }
    public void OnDrag(PointerEventData eventData)
    {
        Vector2 dragPos = Camera.main.ScreenToWorldPoint(eventData.position);

        dragPos.y -= UnitObject.GetComponent <BoxCollider2D>( ).size.y / 3f;

        UnitObject.transform.position = dragPos;
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            DescriptionBar.SetActive(!DescriptionBar.activeInHierarchy);
            InfoBar.SetActive(!InfoBar.activeInHierarchy);
        }


        // When played is pressed, set everything into motion
        if (Input.GetKeyDown("space") &&
            !mActionSelector.GetComponent <ActionSelector>().mPlanningAction&&
            !CheckMoving() &&
            !mInMotion &&
            !mDialogueController.DialogueGoing)
        {
            mInMotion = true;

            // Need to loop through all units and start their motions
            foreach (GameObject FriendlyUnit in mFriendlyUnits)
            {
                if (FriendlyUnit == null)
                {
                    continue;
                }
                Movement FriendlyUnitMovement = FriendlyUnit.GetComponent <Movement>();
                FriendlyUnit.GetComponent <CharacterStats>().mTurnGoing = true;
                FriendlyUnitMovement.mInMotion = true;
                FriendlyUnitMovement.StartMovement();
                FriendlyUnit.GetComponent <BoxCollider2D>().size = new Vector2(.4f, .4f);
            }

            foreach (GameObject EnemyUnit in mEnemyUnits)
            {
                if (EnemyUnit == null)
                {
                    continue;
                }
                Movement EnemyUnitMovement = EnemyUnit.GetComponent <Movement>();
                EnemyUnit.GetComponent <CharacterStats>().mTurnGoing = true;
                EnemyUnitMovement.mInMotion = true;
                EnemyUnitMovement.StartMovement();
                EnemyUnit.GetComponent <BoxCollider2D>().size = new Vector2(.4f, .4f);
            }

            StartCoroutine(RunSequence());
        }

        // Bring up the retry menu
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            QuitMenu.SetActive(!QuitMenu.activeInHierarchy);
        }
    }
    private void Start( )
    {
        PriceText.text = UnitPrefab.Cost.ToString( );

        UnitObject = Instantiate(UnitPrefab, Camera.main.ScreenToWorldPoint(transform.position), Quaternion.identity) as FriendlyUnit;
        UnitObject.transform.position = new Vector3(UnitObject.transform.position.x, UnitObject.transform.position.y, 0f);

        StartingPosition = Camera.main.ScreenToWorldPoint(transform.position);

        UnitObject.GetComponent <BoxCollider2D>( ).enabled = false;
        UnitObject.gameObject.SetActive(false);
    }
Beispiel #5
0
    private void SpawnUnit(FriendlyUnit unit)
    {
        if (unit == null)
        {
            return;
        }

        UnitOnTile = Instantiate(unit, UnitSpawn.transform.position, Quaternion.identity) as FriendlyUnit;
        UnitOnTile.GetComponent <BoxCollider2D>( ).enabled = true;
        UnitOnTile.Init( );

        IsEmpty = false;
        ActiveTile.gameObject.SetActive(false);

        GameManager.OnUnitPurchased.Invoke(unit);
    }
    public void NotifyAction()
    {
        foreach (GameObject FriendlyUnit in mFriendlyUnits)
        {
            if (FriendlyUnit != null)
            {
                FriendlyUnit.GetComponent <CharacterStats>().ActionActivate();
            }
        }

        foreach (GameObject EnemyUnit in mEnemyUnits)
        {
            if (EnemyUnit != null)
            {
                EnemyUnit.GetComponent <CharacterStats>().ActionActivate();
            }
        }
    }
    // Puts all units to sleep when a battle occurs
    public void SleepAll()
    {
        foreach (GameObject FriendlyUnit in mFriendlyUnits)
        {
            if (FriendlyUnit != null)
            {
                FriendlyUnit.GetComponent <Movement>().mPause = true;
            }
        }

        foreach (GameObject EnemyUnit in mEnemyUnits)
        {
            if (EnemyUnit != null)
            {
                EnemyUnit.GetComponent <Movement>().mPause = true;
            }
        }
    }
    // Puts all units to sleep when a battle occurs
    public void WakeAll()
    {
        foreach (GameObject FriendlyUnit in mFriendlyUnits)
        {
            if (FriendlyUnit != null)
            {
                FriendlyUnit.GetComponent <Movement>().mPause = false;
            }
        }

        foreach (GameObject EnemyUnit in mEnemyUnits)
        {
            if (EnemyUnit != null)
            {
                EnemyUnit.GetComponent <Movement>().mPause = false;
            }
        }
        mCamera.StartZoomOut();
    }