コード例 #1
0
    private float _timer;     // provides delay between attacks


    void Awake()
    {
        _player          = GameObject.FindGameObjectWithTag("Player");
        _playerLifecycle = _player.GetComponent <TankLifecycle>();
        _enemyLifecycle  = GetComponent <EnemyLifecycle>();
        _anim            = GetComponent <Animator>();
    }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        var colliders = Physics.OverlapSphere(transform.position, explosionRadius, obstacleMask);

        foreach (Collider c in colliders)
        {
            Rigidbody targetRigidbody = c.GetComponent <Rigidbody>();
            if (!targetRigidbody)
            {
                continue;
            }

            targetRigidbody.AddExplosionForce(explosionForce, transform.position, explosionRadius);

            EnemyLifecycle enemy = targetRigidbody.GetComponent <EnemyLifecycle>();
            if (!enemy)
            {
                continue;
            }

            float damage = CalculateDamage(targetRigidbody.transform.position);
            enemy.TakeDamage(damage);
        }

        explosionParticles.transform.parent = null;
        explosionParticles.Play();
        explosionAudio.Play();

        _renderer.enabled    = false;
        _rb.detectCollisions = false;
        _rb.velocity         = Vector3.zero;
        StartCoroutine(ResetParticles(explosionParticles.main.duration));
    }
コード例 #3
0
 private void Awake()
 {
     _player          = GameObject.FindGameObjectWithTag("Player").transform;
     _playerLifecycle = _player.GetComponent <TankLifecycle>();
     _lifecycle       = GetComponent <EnemyLifecycle>();
     _nav             = GetComponent <NavMeshAgent>();
 }
コード例 #4
0
    private void Awake()
    {
        lifecycle     = GetComponent <EnemyLifecycle>();
        nav           = GetComponent <NavMeshAgent>();
        originalSpeed = nav.speed;

        mat = GetMaterial();
        mat.EnableKeyword("_EMISSION");
    }
コード例 #5
0
    protected virtual void HandleHit()
    {
        EnemyLifecycle enemyLifecycle = shootHit.collider.GetComponent <EnemyLifecycle>();

        if (enemyLifecycle != null)
        {
            enemyLifecycle.TakeDamage(damage);
        }

        _gunLine.SetPosition(1, shootHit.point);
    }
コード例 #6
0
ファイル: Gun.cs プロジェクト: IfreannMedia/Invasion
    //-----------------------------------------------------------------------------------------------------
    // Method: HitEnemy()
    // Desc:   Takes health away from EnemyLifeCycle.cs, triggers enemy to be killed if applicable
    //         Uses whichever particleEffect for the hit animation that we pass in. This is
    //         decided in conditional logic of FireWeapon(). Also handles shooting outside effective range
    //-----------------------------------------------------------------------------------------------------
    protected void HitEnemy(Collider hitCol, Transform particleEffect, bool insideEffectiveRange)
    {
        EnemyLifecycle EnemyLifeScript = hitCol.GetComponentInParent <EnemyLifecycle>();

        if (insideEffectiveRange) // we have shot in the effective range:
        {
            if (EnemyLifeScript.EnemyHealth > 0)
            {
                Vector3 direction = EnemyLifeScript.transform.position - transform.position;

                EnemyLifeScript.TakeDamage(Damage, direction, StoppingPower, hitCol, EnemyLifecycle.ScoreAmount.bodyShotScore);
            }
            else if (EnemyLifeScript.EnemyHealth < 0)
            {
                Vector3   direction = EnemyLifeScript.transform.position - transform.position;
                Rigidbody rb        = hitCol.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    rb.AddRelativeForce(direction * StoppingPower, ForceMode.VelocityChange);
                }
            }
        }
        else // we have hit something in the non-effective range:
        {
            if (EnemyLifeScript.EnemyHealth > 0)
            {
                Vector3 direction = EnemyLifeScript.transform.position - transform.position;
                // deal one tenth of possible damage and half of the possible stopping power
                // however still get full point value for a succesful hit:
                EnemyLifeScript.TakeDamage(Damage * 0.1f, direction, StoppingPower * 0.5f, hitCol, EnemyLifecycle.ScoreAmount.bodyShotScore);
                ;
            }
            // If we are shooting a corpse on the ground, addRelativeForce to move it a bit:
            else if (EnemyLifeScript.EnemyHealth < 0)
            {
                Vector3   direction = EnemyLifeScript.transform.position - transform.position;
                Rigidbody rb        = hitCol.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    rb.AddRelativeForce(direction * StoppingPower, ForceMode.VelocityChange);
                }
            }
        }
        // Use the particle effect from the pool:
        Transform hitEffect = ObjectPooler.UseObject(particleEffect, ShotHit.point, true);

        hitEffect.rotation = Quaternion.LookRotation(ShotHit.normal);
    }
コード例 #7
0
ファイル: Gun.cs プロジェクト: IfreannMedia/Invasion
    //-----------------------------------------------------------------------------------------------------
    // Method: HitFlamerArmour()
    // Desc:   Same code as in HitEnemy(), but as the flamer enemy wears heavy armour, bullets may not
    //         penetrate it and so deal very little damage. Damage can only really be dealt to flamer enemy
    //         by hitting his energy pack
    //-----------------------------------------------------------------------------------------------------
    protected void HitFlamerArmour(Collider hitCol, Transform particleEffect, bool insideEffectiveRange)
    {
        EnemyLifecycle EnemyLifeScript = hitCol.GetComponentInParent <EnemyLifecycle>();

        if (insideEffectiveRange)
        {
            if (EnemyLifeScript.EnemyHealth > 0)
            {
                Vector3 direction = EnemyLifeScript.transform.position - transform.position;
                EnemyLifeScript.TakeDamage(Damage * 0.05f, direction, StoppingPower, hitCol);
            }
            else if (EnemyLifeScript.EnemyHealth < 0)
            {
                Vector3   direction = EnemyLifeScript.transform.position - transform.position;
                Rigidbody rb        = hitCol.GetComponent <Rigidbody>();

                if (rb != null)
                {
                    rb.AddForce(direction * StoppingPower);
                }
            }
        }
        else
        {
            if (EnemyLifeScript.EnemyHealth > 0)
            {
                Vector3 direction = EnemyLifeScript.transform.position - transform.position;
                EnemyLifeScript.TakeDamage(Damage * 0.05f, direction, StoppingPower, hitCol);
            }
            else if (EnemyLifeScript.EnemyHealth < 0)
            {
                Vector3   direction = EnemyLifeScript.transform.position - transform.position;
                Rigidbody rb        = hitCol.GetComponent <Rigidbody>();

                if (rb != null)
                {
                    rb.AddForce(direction * StoppingPower);
                }
            }
        }

        Transform hitEffect = ObjectPooler.UseObject(particleEffect, ShotHit.point, true);

        hitEffect.rotation = Quaternion.LookRotation(ShotHit.normal);
    }
コード例 #8
0
ファイル: Gun.cs プロジェクト: IfreannMedia/Invasion
    //--------------------------------------------------------------------------------------------
    // Method: HeadshotEnemy()
    // Desc:   Takes health away from EnemyLifeCycle.cs, triggers enemy to be killed if applicable
    //         Uses whichever particleEffect for the hit animation that we pass in. This is
    //         decided in conditional logic of FireWeapon(). Adds a headshot score to score counter
    //         Tester feedback said it was too easy to get headshots with the pistol from far away
    //         So halve headshot damage if in non-efffective range
    //---------------------------------------------------------------------------------------------
    protected void HeadshotEnemy(Collider hitCol, Transform particleEffect, bool insideEffectiveRange)
    {
        EnemyLifecycle EnemyLifeScript = hitCol.GetComponentInParent <EnemyLifecycle>();

        if (insideEffectiveRange)
        {
            if (EnemyLifeScript.EnemyHealth > 0)
            {
                Vector3 direction = EnemyLifeScript.transform.position - transform.position;
                EnemyLifeScript.TakeDamage(HeadshotDamage, direction, StoppingPower, hitCol, EnemyLifecycle.ScoreAmount.HeadShotScore);
            }
            else if (EnemyLifeScript.EnemyHealth < 0)
            {
                Vector3   direction = EnemyLifeScript.transform.position - transform.position;
                Rigidbody rb        = hitCol.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    rb.AddRelativeForce(direction * StoppingPower, ForceMode.VelocityChange);
                }
            }
        }
        else
        {
            if (EnemyLifeScript.EnemyHealth > 0)
            {
                Vector3 direction = EnemyLifeScript.transform.position - transform.position;
                EnemyLifeScript.TakeDamage(HeadshotDamage * 0.25f, direction, StoppingPower, hitCol, EnemyLifecycle.ScoreAmount.HeadShotScore);
            }
            else if (EnemyLifeScript.EnemyHealth < 0)
            {
                Vector3   direction = EnemyLifeScript.transform.position - transform.position;
                Rigidbody rb        = hitCol.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    rb.AddRelativeForce(direction * StoppingPower, ForceMode.VelocityChange);
                }
            }
        }

        Transform hitEffect = ObjectPooler.UseObject(particleEffect, ShotHit.point, true);

        hitEffect.rotation = Quaternion.LookRotation(ShotHit.normal);
    }
コード例 #9
0
    private void HitEnemy(Collider other)
    {
        //PlayerStats.Score += _punchScore;
        //_scoreText.text = "Score: " + PlayerStats.Score.ToString();
        //Transform particleEffect = ObjectPooler.UseObject(meleeEffectPool.transform, other.ClosestPointOnBounds(transform.position));
        //Transform particleEffect = ObjectPooler.UseObject(meleeEffectPool.transform, other.ClosestPoint(transform.position));
        Transform particleEffect = ObjectPooler.UseObject(meleeEffectPool.transform, _impactEffect.transform.position);

        particleEffect.GetComponent <ParticleSystem>().Play();
        particleEffect.GetComponent <AudioSource>().pitch = Random.Range(0.78f, 1.10f);
        particleEffect.GetComponent <AudioSource>().Play();
        EnemyLifecycle enemyLifeScript = other.GetComponentInParent <EnemyLifecycle>(); // For some reason this will not find the enemyLifecycle script

        if (enemyLifeScript)
        {
            if (enemyLifeScript.EnemyHealth > 0.0f)
            {
                Vector3 direction = other.transform.position = transform.position;
                enemyLifeScript.TakeDamage(Damage, direction, force, other, EnemyLifecycle.ScoreAmount.punchScore);
                //enemyLifeScript.GetComponent<Animator>().SetTrigger("KnockBack");
            }
        }
        GetComponent <Collider>().enabled = false;
    }