Beispiel #1
0
    void OnMouseUp()
    {
        if (selected)
        {
            selected = false;

            transform.position = myHUDPosition;

            myRenderer.enabled = true;

            playerStatsScript.hideManaToSpend();

            if (playerStatsScript.currentMana >= myCardStats.cost && backgroundMouseFlag.mouseIsOver)
            {
                playerStatsScript.SpendMana(myCardStats.cost);

                if (myCardStats.type == "Spell")
                {
                    areaOfEffect.layer = 0;                     // Layer 0 == Default
                    Collider2D[] overlappingColliders = new Collider2D[GameObject.FindGameObjectsWithTag("EnemyUnit").Length * 2];

                    areaOfEffect.GetComponent <CircleCollider2D>().OverlapCollider(new ContactFilter2D(), overlappingColliders);

                    List <GameObject> enemiesInRange = new List <GameObject>();

                    for (int i = 0; i < overlappingColliders.Length; i++)
                    {
                        if (overlappingColliders[i])
                        {
                            if (!overlappingColliders[i].isTrigger && overlappingColliders[i].gameObject.tag == "EnemyUnit")
                            {
                                enemiesInRange.Add(overlappingColliders[i].gameObject);
                            }
                        }
                    }

                    if (enemiesInRange.Count > 0)
                    {
                        myCardEffects.RunCardEffects(myCardStats, enemiesInRange);
                    }

                    areaOfEffect.SetActive(false);
                }

                if (listOfAlliedUnitsToSpawn.Count > 0)
                {
                    for (int i = 0; i < listOfAlliedUnitsToSpawn.Count; i++)
                    {
                        listOfAlliedUnitsToSpawn[i].GetComponent <AllyBehavior>().isSpawned = true;
                        listOfAlliedUnitsToSpawn[i].layer = 0;                         // Layer 0 == Default
                        listOfAlliedUnitsToSpawn[i].GetComponent <AllyBehavior>().Summoned(myCardStats.health, myCardStats.attackDamage, myCardStats.attackSpeed, myCardStats.moveSpeed);
                    }

                    listOfAlliedUnitsToSpawn.Clear();
                }

                myCardStats.toRemove = true;
            }
            else
            {
                if (myCardStats.type == "Spell")
                {
                    areaOfEffect.SetActive(false);
                }
                else
                {
                    if (listOfAlliedUnitsToSpawn.Count > 0)
                    {
                        for (int i = 0; i < listOfAlliedUnitsToSpawn.Count; i++)
                        {
                            Destroy(listOfAlliedUnitsToSpawn[i].gameObject);
                        }

                        listOfAlliedUnitsToSpawn.Clear();
                    }
                }
            }
        }
    }