Example #1
0
    private void AttackEnemy(RaycastHit hit)
    {
        Vector3 distance = new Vector3();

        distance = hit.collider.transform.position - transform.position;
        if (Mathf.Abs(distance.magnitude) <= this.GetComponent <FieldOfView>().viewRadius)
        {
            if (Mathf.Abs(distance.magnitude) >= 3)
            {
                Weapon.setGunVisible(true);
                hit.collider.GetComponent <BaseStats>().HP -= this.GetComponent <BaseStats>().RangeAtack;
                CharacterAnimController.isShooting          = true;
            }
            else if (Mathf.Abs(distance.magnitude) < 3)
            {
                hit.collider.GetComponent <BaseStats>().HP -= this.GetComponent <BaseStats>().MeleAtack;
                CharacterAnimController.isPunching          = true;
            }

            alredyAttack = true;
        }

        UnitMovement unit = hit.collider.GetComponent <UnitMovement>();

        if (unit.GetComponent <BaseStats>().HP <= 0)
        {
            RingSelectedEnemy.SetDeactiveRing();
            UnitIsAlive(unit);
        }
        else if (alredyAttack)
        {
            unit.GetComponentInChildren <ZombieAnimatorController>().lateHitAnimation = true;
        }
    }
Example #2
0
    private void RunIfMoveAction(RaycastHit hit)
    {
        RingSelectedEnemy.SetDeactiveRing();

        Tile t = hit.collider.GetComponent <Tile>();

        if (t.selectable)
        {
            if (currentSelectedObj == SelectedObj.tile && t.GetComponent <Renderer>().material.color == Color.blue)
            {
                t.GetComponent <Renderer>().material.color = Color.green;
                currentSelectedObj = SelectedObj.none;
                MoveToTile(t);
            }
            currentSelectedObj = SelectedObj.tile;

            if (t.GetComponent <Renderer>().material.color != Color.blue && t.GetComponent <Renderer>().material.color != Color.green)
            {
                foreach (Tile tile in selectableTiles)
                {
                    if (tile.GetComponent <Renderer>().material.color == Color.blue)
                    {
                        tile.GetComponent <Renderer>().material.color = Color.red;
                    }
                }
                t.GetComponent <Renderer>().material.color = Color.blue;
            }
        }
    }
Example #3
0
    private void RunIfAttackAction(RaycastHit hit)
    {
        if (hit.collider.GetComponent <BaseStats>().HP > 0)
        {
            removeSelectedTileByMouse();

            RingSelectedEnemy.SetActiveRing();

            heading = hit.collider.transform.position - transform.position;
            heading.Normalize();
            transform.forward = heading;

            if (currentSelectedObj == SelectedObj.enemy && RingInTheSamePosition(hit))
            {
                currentSelectedObj = SelectedObj.none;
                RingSelectedEnemy.SetDeactiveRing();
                AttackEnemy(hit);
            }
            currentSelectedObj = SelectedObj.enemy;

            if (hit.collider.gameObject.transform.position != RingSelectedEnemy.GetRingPosition())
            {
                RingSelectedEnemy.GetEnemyPosition(hit.collider.GetComponent <UnitMovement>());
            }
        }
    }
Example #4
0
    private bool RingInTheSamePosition(RaycastHit hit)
    {
        if (hit.collider.gameObject.transform.position.x == RingSelectedEnemy.GetRingPosition().x)
        {
            if (hit.collider.gameObject.transform.position.z == RingSelectedEnemy.GetRingPosition().z)
            {
                if (RingSelectedEnemy.GetRingPosition().y > 0)
                {
                    return(true);
                }
            }
        }

        return(false);
    }