private void EnemyReachedCastle(EnemyController _enemy)
    {
        CastleController c = castles[_enemy.PathwayIndex];

        CheckWave();

        if (c.TakeDamage(_enemy.enemy.damage))
        {
            GameOver();
        }
    }
Ejemplo n.º 2
0
    IEnumerator Attack(CardController attacker)
    {
        Transform originalTransform = new GameObject().transform;

        originalTransform.position = attacker.transform.position;
        originalTransform.rotation = attacker.transform.rotation;

        while (true)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            Physics.Raycast(ray, out hit, 100.0f, LayerMask.GetMask("GameBoard"));

            Vector3 newPosition = originalTransform.position - .3f * (originalTransform.position - hit.point);
            attacker.transform.position = newPosition;
            attacker.transform.LookAt(transform);

            if (Physics.Raycast(ray, out hit))
            {
                CardController attacked = hit.transform.gameObject.GetComponent <CardController>();
                if (otherPlayer.cardsOnTheTable.Contains(attacked) && (Input.GetMouseButtonUp(1)) &&
                    attacked.layer == otherPlayer.getAttackLayer())
                {
                    Transform targetTransform = new GameObject().transform;
                    targetTransform.position = attacked.gameObject.transform.position;
                    targetTransform.LookAt(transform);

                    yield return(StartCoroutine(Move(attacker.gameObject.transform, targetTransform)));

                    attacker.Attack(attacked);

                    GameObject.Destroy(targetTransform.gameObject);
                    break;
                }
                else if (enemyCastle.hitCastle(hit.transform) && Input.GetMouseButtonUp(1))
                {
                    Debug.Log("Attacking castle");
                    yield return(StartCoroutine(Move(attacker.transform, enemyCastle.transform)));

                    enemyCastle.TakeDamage(attacker.attack);
                    break;
                }

                else if (Input.GetKeyUp(KeyCode.Escape))
                {
                    break;
                }
            }

            yield return(null);
        }

        yield return(null); // gives time fpr destruction of attacking card

        if (attacker != null)
        {
            Debug.Log("Attacker is not null");
            yield return(StartCoroutine(Move(attacker.transform, originalTransform)));
        }
        GameObject.Destroy(originalTransform.gameObject);
        unblocked = true;
    }