Ejemplo n.º 1
0
    public override BaseDamagable GetTarget()
    {
        BaseDamagable damagable = null;

        var closeObjects = Physics2D.CircleCastAll(transform.position, gunRange,
                                                   transform.up, gunRange, possibleTargets.value);

        foreach (var collider in closeObjects)
        {
            if (collider.rigidbody == null)
            {
                // Not a valid target
                continue;
            }

            damagable = collider.rigidbody.GetComponent <BaseDamagable>();

            if (damagable == null)
            {
                // Not a valid target
                continue;
            }

            // if we reached this, we have a valid target
            break;
        }

        // If no target was found, damagable will be null (that's ok)
        return(damagable);
    }
Ejemplo n.º 2
0
 protected override void FireOnTarget(BaseDamagable target)
 {
     if (target != null)
     {
         target.TakeDamage(gunDamage);
     }
 }
Ejemplo n.º 3
0
    protected override void FireOnTarget(BaseDamagable target)
    {
        var missile = MasterPooler.Get <Missile>(transform.position, transform.rotation);

        if (target == null)
        {
            Debug.Log("Faulty");
            missile.LaunchMissile(this, null, 2);
            return;
        }

        missile.LaunchMissile(this, target, 6);
    }
Ejemplo n.º 4
0
    protected override void OnUpdate()
    {
        if (!_isActive)
        {
            return;
        }

        if (Time.time > _detonationTime)
        {
            Explode();
            return;
        }

        _rigidbody.AddForce(transform.up * _speed);

        // If target was destroyed or missing, go faulty
        if (_target == null)
        {
            // Try to find new target
            _target = _owner.GetTarget();

            // if target is still null, go faulty
            if (_target == null)
            {
                transform.Rotate(Vector3.forward * Time.deltaTime * 300);
                return;
            }
        }

        if (_seeking)
        {
            var targetDirection = _target.transform.position - transform.position;

            transform.RotateTowards(targetDirection, _turn * Time.deltaTime);
        }
    }
Ejemplo n.º 5
0
 protected virtual void FireOnTarget(BaseDamagable target)
 {
     Debug.LogWarning("BaseGun FireOnTarget");
 }
Ejemplo n.º 6
0
    protected override void FireOnTarget(BaseDamagable target)
    {
        var bomb = MasterPooler.Get <Bomb>(transform.position, transform.rotation);

        bomb.LaunchBomb(this, 20);
    }
Ejemplo n.º 7
0
 public void LaunchMissile(BaseGun owner, BaseDamagable target, float missileTimeout)
 {
     _target = target;
     _owner  = owner;
     LaunchMissile(missileTimeout);
 }