Пример #1
0
    private void SpellCast()
    {
        if (GetGridPosition() != null)
        {
            Vector3 position = GetGridPosition().Value;
            if (spellTarget != null && CheckFloor(position.y))
            {
                //Spell comes from right side
                if (spellDirection == SpellDirection.Right)
                {
                    switch (PlayerOneState)
                    {
                    case 1:
                        castedSpell    = spell.InstantiateSpell(50, spellTarget.transform.position.y, -42);
                        movementVector = new Vector3(-spellSpeed, 0, 0);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;

                    case 2:
                        castedSpell    = spell.InstantiateSpell(42, spellTarget.transform.position.y, 50);
                        movementVector = new Vector3(0, 0, -spellSpeed);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;

                    case 3:
                        castedSpell    = spell.InstantiateSpell(-50, spellTarget.transform.position.y, 42);
                        movementVector = new Vector3(spellSpeed, 0, 0);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;

                    case 4:
                        castedSpell    = spell.InstantiateSpell(-42, spellTarget.transform.position.y, -50);
                        movementVector = new Vector3(0, 0, spellSpeed);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;
                    }
                    castedSpell.GetComponent <SpellBase>().SpellCast = true;
                }
                if (spellDirection == SpellDirection.Instant)
                {
                    castedSpell = spell.InstantiateSpell(spell.transform.position);
                    castedSpell.GetComponent <SpellBase>().SpellCast = true;
                }
                if (spellDirection == SpellDirection.Ceiling)
                {
                    switch (PlayerOneState)
                    {
                    case 1:
                        castedSpell    = spell.InstantiateSpell(spellTarget.transform.position.x, spellTarget.transform.position.y + verticalSpellSpawnHeight, -42);
                        movementVector = new Vector3(0, -spellSpeed, 0);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;

                    case 2:
                        castedSpell    = spell.InstantiateSpell(42, spellTarget.transform.position.y + verticalSpellSpawnHeight, spellTarget.transform.position.z);
                        movementVector = new Vector3(0, -spellSpeed, 0);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;

                    case 3:
                        castedSpell    = spell.InstantiateSpell(spellTarget.transform.position.x, spellTarget.transform.position.y + verticalSpellSpawnHeight, 42);
                        movementVector = new Vector3(0, -spellSpeed, 0);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;

                    case 4:
                        castedSpell    = spell.InstantiateSpell(-42, spellTarget.transform.position.y + verticalSpellSpawnHeight, spellTarget.transform.position.z);
                        movementVector = new Vector3(0, -spellSpeed, 0);
                        rb             = castedSpell.GetComponent <Rigidbody>();
                        break;
                    }
                    castedSpell.GetComponent <SpellBase>().SpellCast = true;
                }
                StartCoroutine(StartCooldown(spell.GetComponent <SpellBase>().CooldownTime, queue[queueIndex].transform.localPosition, queueIndex));

                spell = null;

                ClearButton();

                DestroyTarget();

                SetSelectedButton();
            }
        }
    }