Exemple #1
0
    public override void Fire(Vector3 target)
    {
        if (_runtime.GetEnemyTarget() is Enemy enemy)
        {
            if (!enemy)
            {
                return;
            }

            if (Vector3.Distance(enemy.transform.position, transform.position) <= _range && canFire)
            {
                RaycastHit hit = new RaycastHit();
                Physics.Raycast(transform.position, transform.forward, out hit, 999f);

                enemy.BroadcastMessage("OnHit", _damage);
                enemy.GetComponent <Rigidbody>().AddExplosionForce(_force, hit.point, _range);

                canFire    = false;
                timeToFire = 1 / fireRate;
            }
        }
    }