コード例 #1
0
    private void OnTriggerEnter(Collider other)
    {
        // Damage the enemy if we hit one, destroy ourselves
        EnemyHealth enemy = other.GetComponent <EnemyHealth>();

        if (enemy != null)
        {
            enemy.DamageEnemy(m_damage);
            Destroy(gameObject);
        }
        // Since in the second scene I will be using the same bullet "misiles" for both the player and the boss..
        // I will check if he hit a Boss or the Player and remove health from it.
        if (other.gameObject.CompareTag("Boss"))
        {
            if (other.GetComponent <Boss1>() != null)
            {
                other.GetComponent <Boss1>().DamangeBoss(m_damage);
            }
            if (other.GetComponent <Boss2>() != null)
            {
                other.GetComponent <Boss2>().DamangeBoss(m_damage);
            }
            Destroy(gameObject);
        }

        if (other.gameObject.CompareTag("Player"))
        {
            Debug.Log("Hit the player. Deal damage.");
            other.gameObject.GetComponent <Player_Stats>().TakeDamage(5);
            Destroy(this.gameObject);
        }
    }
コード例 #2
0
 //Check if you dealt damage to an enemy or hit any button
 private void CheckForDamage(GameObject hitObject)
 {
     if (hitObject.CompareTag("Enemy"))
     {
         EnemyHealth enemy = hitObject.GetComponent <EnemyHealth>();
         m_enemiesKilled += enemy.DamageEnemy(this);
         Debug.Log(m_enemiesKilled);
     }
     else if (hitObject.CompareTag("PlayButton"))
     {
         Debug.Log("Play");
         Invoke("Play", 0.1f);
     }
     else if (hitObject.CompareTag("MainMenu"))
     {
         if (SceneManager.GetActiveScene().buildIndex == 1)
         {
             PlayerPrefs.SetInt("LastScore", m_enemiesKilled);
         }
         Invoke("MainMenu", 0.1f);
     }
     else if (hitObject.CompareTag("QuitButton"))
     {
         Invoke("Quit", 0.5f);
     }
     else if (hitObject.CompareTag("ResetButton"))
     {
         score.Reset();
     }
 }
コード例 #3
0
ファイル: ExploderFunction.cs プロジェクト: mr0w3m/DiscoShips
    IEnumerator DestroyThis()
    {
        Instantiate(explosionParticles, transform.position, Quaternion.identity);
        yield return(new WaitForSeconds(2f));

        healthScript.DamageEnemy(12);
    }
コード例 #4
0
ファイル: Bullet.cs プロジェクト: muhahaha100/Infinity-Rush
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.tag == "Enemy")
     {
         EnemyHealth enemyHealth = collision.collider.GetComponent <EnemyHealth>();
         enemyHealth.DamageEnemy(damage);
         Destroy(gameObject);
     }
 }
コード例 #5
0
    void GiveEnemyDamage()
    {
        EnemyHealth enemyHealth = hit.collider.GetComponent <EnemyHealth>();

        if (enemyHealth != null)
        {
            enemyHealth.DamageEnemy(_weaponDamage);
        }
    }
コード例 #6
0
    private void OnTriggerEnter(Collider other)
    {
        // Damage the enemy if we hit one, destroy ourselves
        BoomParticle.transform.position = EnemyPos.transform.position;
        BoomPs.Play();
        EnemyHealth enemy = other.GetComponent <EnemyHealth>();

        if (enemy != null)
        {
            enemy.DamageEnemy(m_damage);
            Destroy(gameObject);
        }
    }
コード例 #7
0
    private void FrontHandBackhand(Transform closest)
    {
        Rigidbody rb = closest.GetComponent <Rigidbody>();

        if (rb != null)
        {
            rb.AddExplosionForce(200f, closest.position, 2f, 3f, ForceMode.Impulse);
            EnemyHealth enemyHealth = rb.GetComponent <EnemyHealth>();
            if (enemyHealth != null)
            {
                enemyHealth.DamageEnemy(10);
                Debug.Log("Enemy just got punched in the face!! :))");
            }
        }
    }
コード例 #8
0
    // Handle collisions
    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "Enemy")
        {
            // Damage object with relevant tag
            EnemyHealth health = col.gameObject.GetComponent <EnemyHealth>();
            health.DamageEnemy(DamageAmount);

            // record enemy hit
            _enemiesHit++;

            if (_enemiesHit >= EnemiesThreshold)
            {
                // Destroy self (i.e. the projectile)
                Destroy(this.gameObject);
            }
        }
    }
コード例 #9
0
    private void DetonateExplosion()
    {
        MineManager.instance.PLAY_BOOM_SOUND();
        // SPAWN EFFECT
        EXPLOSION_EFFECT();
        Destroy(gameObject, .5f);

        // ADD FORCE TO OBJECTS

        Collider[] colliders = Physics.OverlapSphere(transform.position, damage_radius);
        foreach (Collider collider in colliders)
        {
            Rigidbody rb = collider.transform.root.gameObject.GetComponent <Rigidbody>();
            if (rb != null)
            {
                rb.AddExplosionForce(explosion_force, transform.position, damage_radius);

                EnemyHealth health = rb.GetComponent <EnemyHealth>();
                health.DamageEnemy(explosion_damage);
            }
        }
    }
コード例 #10
0
    void OnTriggerEnter2D(Collider2D coll)
    {
        //Debug.Log (coll.gameObject.name+", "+coll.gameObject.tag);
        if (coll.gameObject.tag == ("Enemy"))
        {
            PlayBloodSpray();
            Destroy(gameObject);

            EnemyHealth enemyHealth = coll.gameObject.GetComponent <EnemyHealth> ();
            if (enemyHealth != null)
            {
                //Debug.Log ("We Hit " + hit.collider.name + " and did " + damageQuota + " damage.");
                enemyHealth.DamageEnemy(damageQuota);
            }
        }

        if (coll.gameObject.tag == ("Object"))
        {
            //Debug.Log(coll.gameObject.name+", "+coll.gameObject.tag);
            PlayBulletSparks();
            Destroy(gameObject);
        }

        if (coll.gameObject.tag == ("Destructible"))
        {
            PlayExplosion();
            Destroy(coll.gameObject);
            Destroy(gameObject);
            CamShakeEffect();
            audioManager.PlaySound("Explosion");
        }
        else
        {
            Destroy(gameObject, 3f);
        }
    }
コード例 #11
0
ファイル: LineSniperShot.cs プロジェクト: mr0w3m/DiscoShips
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Boundary" || other.tag == "MineralPickup" || other.tag == "Capsule" || other.tag == "Edge" || other.tag == "BoostHit" || other.tag == "AutoTurret")
     {
         //Debug.Log("hit boundary/mineralpickup/capsule/edge");
         return;
     }
     else if (other.tag == "Player1(Black)" || other.tag == "Player2(White)" || other.tag == "Player3" || other.tag == "Player4")
     {
         //Debug.Log("SniperHit " + other.tag);
         enemyHealthScript = other.GetComponent <PlayerHealth>();
         if (enemyHealthScript.teamCount != teamCount)
         {
             enemyHealthScript.Damage(lineSniperShotDamage, false);
             DestroyThis();
         }
     }
     else if (other.tag == "Enemy")
     {
         aiHealthScript = other.GetComponent <EnemyHealth>();
         aiHealthScript.DamageEnemy(lineSniperShotDamage);
         DestroyThis();
     }
     else if (other.tag == "PlayerPhysicsCollider")
     {
         //Debug.Log("SniperHit " + other.tag);
         enemyHealthScript = other.GetComponentInParent <PlayerHealth>();
         if (enemyHealthScript.teamCount != teamCount)
         {
             enemyHealthScript.Damage(lineSniperShotDamage, false);
             DestroyThis();
         }
     }
     else if (other.tag == "RocketAmmo")
     {
         rocketScript = other.GetComponent <RemoteLauncherShot>();
         if (rocketScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "SniperBullet")
     {
         bulletScript = other.GetComponent <LineSniperShot>();
         if (bulletScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Shot")
     {
         shotScript = other.GetComponent <ProtoShotPrefab>();
         if (shotScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "ShieldMine")
     {
         mineScript = other.GetComponent <ShieldMine>();
         if (mineScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Asteroid")
     {
         //Debug.Log("hit asteroid");
         asteroidScript = other.GetComponent <Asteroid>();
         asteroidScript.DamageAsteroid(lineSniperShotDamage);
         pierceCount                -= 1;
         instance                    = Instantiate(deathParticles, transform.position, Quaternion.identity) as GameObject;
         deathParticleSys            = instance.GetComponent <ParticleSystem>();
         deathParticleSys.startColor = color;
         if (pierceCount < 1)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Plasma")
     {
     }
     else if (other.tag == "PhaseBlast")
     {
     }
     else
     {
         //Debug.Log("hit " + other.tag);
         DestroyThis();
     }
 }
コード例 #12
0
    private void Update()
    {
        if (!arrived)
        {
            flightTimer += Time.deltaTime;

            // Move the Arrow along the Parabola
            transform.position = MathParabola.Parabola(startPoint, target, (targetDistance / 5f) * hightMultiplier, flightTimer * speedToDistance);

            // The direction the Arrow is currently flying
            Vector3 direction = transform.position - lastPosition;

            // Collision detection with raycast
            RaycastHit hit = new RaycastHit();
            if (Physics.Raycast(new Ray(lastPosition, direction), out hit, direction.magnitude))
            {
                // Only collide with objects that are not tagged with "Projectile" and not the owner
                // Here you might want to add more things the Arrow should ignore
                if (hit.collider.tag != "Projectile" && hit.collider != ownerCollider && hit.collider.tag != "collectable")
                {
                    Arrive(hit);
                    GameObject hitPrefab   = Instantiate(hitEffect, hit.point, Quaternion.identity);
                    float      destroyTime = isSpecialAttack ? 4f : 2.5f;
                    Destroy(hitPrefab, destroyTime);

                    Collider[] colliders = Physics.OverlapSphere(transform.position, effectRadius);

                    foreach (Collider nearByObject in colliders)
                    {
                        // add force
                        Rigidbody rb = nearByObject.transform.root.GetComponent <Rigidbody>();
                        if (rb != null)
                        {
                            float forceToUse = isSpecialAttack ? effectForceSkill02 : effectForceNormal;
                            rb.AddExplosionForce(forceToUse, transform.position, effectRadius);

                            EnemyHealth health = rb.GetComponent <EnemyHealth>();
                            if (health != null)
                            {
                                if (health.health <= 0)
                                {
                                    return;
                                }

                                int damageToUse = isSpecialAttack ? 20 : 5;
                                health.DamageEnemy(damageToUse);
                            }
                        }
                    }

                    if (arrowEffects.Length > 0)
                    {
                        foreach (GameObject effect in arrowEffects)
                        {
                            Destroy(effect);
                        }
                    }

                    //Debug.Log("hit collider tag: " + hit.collider.transform);
                    EnemyHealth enemyHealth = hit.collider.transform.root.GetComponent <EnemyHealth>();
                    if (enemyHealth != null)
                    {
                        //we hitted the enemy somewhere
                        if (hit.collider.tag == "torso")
                        {
                            arrowDamage = 40;
                            //deal 40 damage
                            enemyHealth.DamageEnemy(arrowDamage);
                        }
                        else if (hit.collider.tag == "head")
                        {
                            arrowDamage = 80;
                            //deal 80 damage
                            enemyHealth.DamageEnemy(arrowDamage);
                        }
                        else if (hit.collider.tag == "arms")
                        {
                            arrowDamage = 20;
                            //deal 20 damage
                            enemyHealth.DamageEnemy(arrowDamage);
                        }
                    }
                    //if(hit.collider.transform.root.GetComponent<Rigidbody>() != null)
                    //{
                    //    if (isSpecialAttack)
                    //    {
                    //        hit.collider.transform.root.GetComponent<Rigidbody>().AddExplosionForce(30f, hit.point, 6f, 3f, ForceMode.Impulse);
                    //    }
                    //    else
                    //    {
                    //        hit.collider.transform.root.GetComponent<Rigidbody>().AddExplosionForce(4f, hit.point, 2f, 1.5f, ForceMode.Impulse);
                    //    }
                    //}
                    return;
                }
            }

            // Rotate the arrow
            transform.rotation = Quaternion.LookRotation(direction);

            // Update the lastPosition
            lastPosition = transform.position;
        }
    }
コード例 #13
0
 void BlowUp()
 {
     if (!exploded)
     {
         exploded = true;
         if (this != null)
         {
             Collider2D[] hitThings = Physics2D.OverlapCircleAll(transform.position, blastRadius);
             if (hitThings != null)
             {
                 for (int i = 0; i < hitThings.Length; i++)
                 {
                     if (hitThings[i].tag == "Player1(Black)" || hitThings[i].tag == "Player2(White)" || hitThings[i].tag == "Player3" || hitThings[i].tag == "Player4")
                     {
                         enemyHealthScript = hitThings[i].GetComponent <PlayerHealth>();
                         if (enemyHealthScript.teamCount != teamCount)
                         {
                             enemyHealthScript.Damage(blastDamage, false);
                         }
                     }
                     else if (hitThings[i].tag == "Enemy")
                     {
                         aiHealthScript = hitThings[i].GetComponent <EnemyHealth>();
                         aiHealthScript.DamageEnemy(blastDamage);
                     }
                     else if (hitThings[i].tag == "Asteroid")
                     {
                         asteroidScript = hitThings[i].GetComponent <Asteroid>();
                         asteroidScript.DamageAsteroid(blastDamage);
                     }
                     else if (hitThings[i].tag == "RocketAmmo")
                     {
                         rocketScript = hitThings[i].GetComponent <RemoteLauncherShot>();
                         if (rocketScript.teamCount != teamCount)
                         {
                             rocketScript.DestroyThis();
                         }
                     }
                     else if (hitThings[i].tag == "DamageBug")
                     {
                         damageBugScript = hitThings[i].transform.GetComponent <DamageBug>();
                         if (damageBugScript.teamCount != teamCount)
                         {
                             //damage the bug
                             damageBugScript.DamageThis(blastDamage);
                         }
                     }
                     else if (hitThings[i].tag == "AutoTurretHitBox")
                     {
                         autoTurretScript = hitThings[i].transform.GetComponentInParent <AutoTurret>();
                         if (autoTurretScript != null)
                         {
                             if (autoTurretScript.teamCount != teamCount)
                             {
                                 //damage the Turret
                                 autoTurretScript.DamageThis(blastDamage);
                             }
                         }
                     }
                     else if (hitThings[i].tag == "TripMine")
                     {
                         tripMineScript = hitThings[i].transform.GetComponent <TripMine>();
                         if (tripMineScript.teamCount != teamCount)
                         {
                             //Blow up tripMine
                             tripMineScript.BlowUp();
                         }
                     }
                     else if (hitThings[i].tag == "Junk")
                     {
                         junkScript = hitThings[i].GetComponent <JunkHealth>();
                         junkScript.DamageJunk(blastDamage);
                     }
                 }
                 DestroyThis();
             }
             else
             {
                 //Debug.Log("hit nothin");
             }
             DestroyThis();
         }
     }
 }
コード例 #14
0
ファイル: ProtoShotPrefab.cs プロジェクト: mr0w3m/DiscoShips
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.tag == "Boundary" || other.tag == "MineralPickup" || other.tag == "Capsule" || other.tag == "Edge" || other.tag == "BoostHit" || other.tag == "AutoTurret")
     {
         //Debug.Log("hit boundary/mineralpickup/capsule/edge");
         return;
     }
     else if (other.tag == "Player1(Black)" || other.tag == "Player2(White)" || other.tag == "Player3" || other.tag == "Player4")
     {
         //Debug.Log("ShotHit " + other.tag);
         enemyHealthScript = other.GetComponent <PlayerHealth>();
         if (enemyHealthScript.teamCount != teamCount)
         {
             enemyHealthScript.Damage(shotDamage, false);
             DestroyThis();
         }
     }
     else if (other.tag == "Enemy")
     {
         aiHealthScript = other.GetComponent <EnemyHealth>();
         if (aiHealthScript.teamCount != teamCount)
         {
             aiHealthScript.DamageEnemy(shotDamage);
             DestroyThis();
         }
     }
     else if (other.tag == "PlayerPhysicsCollider")
     {
         //Debug.Log("ShotHit " + other.tag);
         enemyHealthScript = other.GetComponentInParent <PlayerHealth>();
         if (enemyHealthScript.teamCount != teamCount)
         {
             enemyHealthScript.Damage(shotDamage, false);
             DestroyThis();
         }
     }
     else if (other.tag == "RocketAmmo")
     {
         rocketScript = other.GetComponent <RemoteLauncherShot>();
         if (rocketScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "SniperBullet")
     {
         bulletScript = other.GetComponent <LineSniperShot>();
         if (bulletScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Shot")
     {
         shotScript = other.GetComponent <ProtoShotPrefab>();
         if (shotScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "ShieldMine")
     {
         mineScript = other.GetComponent <ShieldMine>();
         if (mineScript.teamCount != teamCount)
         {
             DestroyThis();
         }
     }
     else if (other.tag == "Asteroid")
     {
         //Debug.Log("hit asteroid");
         asteroidScript = other.GetComponent <Asteroid>();
         asteroidScript.DamageAsteroid(shotDamage);
         DestroyThis();
     }
     else if (other.tag == "Plasma")
     {
     }
     else if (other.tag == "PhaseBlast")
     {
     }
     else
     {
         //Debug.Log("hit " +other.tag);
         DestroyThis();
     }
 }