예제 #1
0
    public void Attack()
    {
        Vector2 attackPosition = transform.position;

        if (_paperSoldierAI != null)
        {
            attackPosition = _paperSoldierAI.AttackPosition;
        }

        if (_enemyAI != null)
        {
            attackPosition = _enemyAI.AttackPosition;
        }

        Vector2 attackOrigin = transform.position + transform.right * AttackOriginOffset;

        GameObject newProjectile = Instantiate(ProjectilePrefab, attackOrigin, Quaternion.identity);

        // RANGED
        AttackBase attackBase = newProjectile.GetComponent <AttackBase>();

        attackBase?.Initialize(this.gameObject, this.tag);

        // MELEE
        Explosion explosion = newProjectile.GetComponent <Explosion>();

        explosion?.Initialize(this.gameObject, this.tag);

        newProjectile.transform.LookAt(attackPosition, Vector3.up);

        Vector3 dir   = (Vector3)attackPosition - newProjectile.transform.position;
        float   angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        newProjectile.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    }
예제 #2
0
    protected override void OnImpact()
    {
        GameObject explosionObject = Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);

        AttackBase attackBase = explosionObject.GetComponent <AttackBase>();

        attackBase?.Initialize(_owner, _teamTag);

        if (attackBase == null)
        {
            Explosion explosion = explosionObject.GetComponent <Explosion>();
            explosion?.Initialize(_owner, _teamTag);
        }
    }