protected void AddSpells()
    {
        List <string> spells = GameManager.Instance.GetPlayer().GetSpells();

        foreach (string spell in spells)
        {
            Spell_Button sp_obj = Instantiate(Resources.Load <Spell_Button>("Objects/" + spell + "Icon"));
            sp_obj.transform.SetParent(transform);
            //TODO: make it in order
            sp_obj.transform.localPosition = new Vector3(0.02f, 0.375f, 0);
        }
    }
Exemple #2
0
    private void Update()
    {
        //suspend spell
        if (activeSpell != null)
        {
            if (Input.GetKey("escape"))
            {
                EndSpell();
            }
        }

        //check if enemies are gone
        if (enemies.Count == 0)
        {
            StartCoroutine(EndBattle());
        }

        //get tile pos
        if (moveUI)
        {
            var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            var noZ = new Vector3(pos.x, pos.y);
            mouseCell = room.transform.GetComponent <Grid>().WorldToCell(noZ);
        }

        if (!playerTurn && !enemyMoving)
        {
            enemyMoving = true;
            StartCoroutine(MoveEnemies());
        }
        else if (playerTurn)
        {
            //move player
            if (Input.GetMouseButtonDown(0) && moveUI && !playerMoving)
            {
                if (Math.Abs(ConvertToTiles().x - player_x) <= player.GetMovementRange() * 3 && Math.Abs(ConvertToTiles().y - player_y) <= player.GetMovementRange() * 3)
                {
                    StartCoroutine(MovePlayer(ConvertToTiles()));
                }
            }

            if ((Input.GetKey("m") || GameManager.Instance.GetMove()) && !moveUI && !moveBlock)
            {
                moveUI = true;
                GameManager.Instance.SetFight(false);
                SetupMovementUI();
            }

            if ((Input.GetKey("f") || GameManager.Instance.GetFight()) && !fightUI)
            {
                fightUI = true;
                GameManager.Instance.SetMove(false);
                SetupFightingUI();
            }

            if (fightUI)
            {
                //hit some zombies
                if (Input.GetMouseButtonDown(0))
                {
                    //Get the mouse position on the screen and send a raycast into the game world from that position.
                    Vector2      worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    RaycastHit2D hit        = Physics2D.Raycast(worldPoint, Vector2.zero);

                    //If something was hit, the RaycastHit2D.collider will not be null.
                    if (hit.collider != null)
                    {
                        Spell_Button sb = hit.collider.gameObject.GetComponent <Spell_Button>();
                        if (sb != null)
                        {
                            sb.InvokeSpell();
                        }
                    }
                }
            }
        }
    }