コード例 #1
0
    private void OnTriggerEnter2D(Collider2D enemyColl)
    {
        Vector2 enemySideDistance = hitDistance;

        enemyHP          = enemyColl.gameObject.GetComponentInParent <EnemyHealthManager>();
        bossHP           = enemyColl.GetComponentInParent <BossPatrolManager>();
        bombHP           = enemyColl.GetComponent <BombController>();
        bulletController = enemyColl.GetComponent <BulletHit>();
        if (enemyHP != null)
        {
            if (enemyColl.transform.position.x < transform.position.x)
            {
                enemySideDistance.x *= -1;//is on ur right
            }
            else
            {
                enemySideDistance.x *= 1;//is on ur left
            }
            enemyHP.TakeDamage(damageToGive, knockbackDuration, enemySideDistance, hitStopDuration);
            if (shouldScreenshakeOnHit)
            {
                Screenshake();
            }
            if (player != null)
            {
                player.AddMeter(meterToGive);
            }
        }
        if (bombHP != null)
        {
            if (enemyColl.transform.position.x < transform.position.x)
            {
                enemySideDistance.x *= -1;//is on ur right
            }
            else
            {
                enemySideDistance.x *= 1;//is on ur left
            }
            bombHP.TakeDamage(damageToGive);
            //bombHP.DoStopAndKnockback(knockbackDuration, enemySideDistance, hitStopDuration);
            if (shouldScreenshakeOnHit)
            {
                Screenshake();
            }
        }

        if (bulletController != null)
        {
            bulletController.ReverseForce();
        }

        if (shouldHitStop)
        {
            player.DoHitStop(hitStopDuration);
        }
        if (hitSpark != null)
        {
            hitSpark.Play();
        }
    }
コード例 #2
0
 void OnTriggerEnter2D(Collider2D coll)
 {
     _bh = coll.GetComponent<BulletHit>();
     if(_bh != null) {
         _bh.Hit(this.gameObject);
         Destroy(coll.gameObject);
     }
 }
コード例 #3
0
ファイル: PenetrableCover.cs プロジェクト: wow4all/Scripts
 public BulletHit catchBullet(BulletHit hit)                                 // This is so that the object doesn;t hit itself....
 {
     Physics.Raycast(hit.hit.normal, hit.hit.point + (hit.hit.normal * 2), out hit.hit, hit.maxRange - ((impermeability / 100) * hit.maxRange));
     hit.Damage   = hit.Damage - ((impermeability / 100) * hit.Damage);
     hit.maxRange = hit.maxRange - ((impermeability / 100) * hit.maxRange);
     hit.calculateDamage();
     return(hit);
 }
コード例 #4
0
 void DestroyThis(bool onhit)
 {
     if (onhit)
     {
         BulletHit?.Invoke();
     }
     Destroy(gameObject);
 }
コード例 #5
0
ファイル: Block.cs プロジェクト: demondi666/Fire-Balls-3d
    public void Break()
    {
        BulletHit?.Invoke(this);
        ParticleSystemRenderer particleSystem = Instantiate(_destroyEffect, transform.position, _destroyEffect.transform.rotation).GetComponent <ParticleSystemRenderer>();

        particleSystem.material.color = _renderer.material.color;
        Destroy(gameObject);
    }
コード例 #6
0
ファイル: PenetrableCover.cs プロジェクト: wow4all/Scripts
    public float tolerance = 100; // 100 is unmarred, 0 is gone.

    #endregion Fields

    #region Methods

    public BulletHit catchBullet(BulletHit hit)
    {
        // This is so that the object doesn;t hit itself....
        Physics.Raycast(hit.hit.normal, hit.hit.point + (hit.hit.normal*2), out hit.hit, hit.maxRange - ((impermeability/100)*hit.maxRange));
        hit.Damage = hit.Damage - ((impermeability/100)*hit.Damage);
        hit.maxRange = hit.maxRange - ((impermeability/100)*hit.maxRange);
        hit.calculateDamage();
        return hit;
    }
コード例 #7
0
        private Boolean ExpandableHitCallback(ref BulletHit hitInfo)
        {
            Boolean result = base.DefaultHitCallback(ref hitInfo);

            this.onHit?.Invoke(this, hitInfo);
            if (!result)
            {
                this.onStop?.Invoke(this, hitInfo);
            }
            return(result);
        }
コード例 #8
0
    public void FireBullet()
    {
        turretAnim.Play("Shoot");
        var        offset   = new Vector3(0.5f * direction, 0, 0);
        GameObject bulletGO = Instantiate(bullets[0], transform.position + offset, Quaternion.identity);
        BulletHit  bullet   = bulletGO.GetComponent <BulletHit>();

        bullet.character  = characterObject;
        bullet.bulletType = bulletType;
        bullet.target     = target;
        bulletGO.GetComponent <Hitbox>().character = characterObject;
        bulletGO.transform.localScale = new Vector3(direction, 1, 1);
    }
コード例 #9
0
    /// <summary>
    /// generates a new BulletHit that can be used for calculating reflections and shots.
    /// </summary>
    /// <returns>
    /// The bullet hit generated.
    /// </returns>
    /// <param name='Hit'>
    /// The raycastHit to use.
    /// </param>
    /// <param name='shooter'>
    /// The Enemy that shot the gun.
    /// </param>
    public BulletHit generateHit(RaycastHit Hit, Enemy shooter)
    {
        BulletHit bh = new BulletHit();

        bh.BloodSpray  = BloodSpray;
        bh.BulletHole  = BulletHole;
        bh.caliber     = ammoType;
        bh.Damage      = Damage;
        bh.DirtSpray   = DirtSpray;
        bh.hit         = Hit;
        bh.HitStrength = HitStrength;
        bh.maxRange    = Range;
        bh.origin      = camera.transform.position;
        bh.shooter     = shooter;
        return(bh);
    }
コード例 #10
0
    void ShootWave()
    {
        // ye added shootsound
        if (GetComponentInParent <ShootSound> ())
        {
            GetComponentInParent <ShootSound> ().hackShoot();
        }

        // instantiate the bullet prefabs

        float midAngleZ   = transform.rotation.eulerAngles.z;
        float startAngleZ = midAngleZ - deltaAngle * (bulletCount - 1) / 2.0f;
        float endAngleZ   = midAngleZ + deltaAngle * (bulletCount - 1) / 2.0f;

        for (float angleZ = startAngleZ; angleZ <= endAngleZ; angleZ += deltaAngle)
        {
            Quaternion newBulletRot = transform.rotation;
            Vector3    shooterEuler = transform.rotation.eulerAngles;
            newBulletRot.eulerAngles = new Vector3(shooterEuler.x, shooterEuler.y, angleZ);
            GameObject bulletObj = Instantiate(bulletPrefab, transform.position, newBulletRot);

            // set init velocity of the bullet
            bulletObj.GetComponent <Rigidbody2D> ().velocity = bulletObj.transform.up.normalized * initialVelocity;

            BulletHit bulletHit = bulletObj.GetComponent <BulletHit> ();
            if (bulletHit)
            {
                Debug.Log("Set init velo");
                bulletHit.initVelocity = transform.up.normalized;

                // Debug.Log (bulletObj.transform.up.normalized);
            }
            // tell the bulletObj the init velocity
            //bulletObj.GetComponent<BulletDeflect> ().initialVelocity = initialVelocity;
        }

        // play shoot sound
        myAudioSource.PlayOneShot(shootSound);

        isCooledDown = false;

        Invoke("CoolDown", coolDownDelay);
        //}
    }
コード例 #11
0
ファイル: Block.cs プロジェクト: lg-lg-lg/ballgun3d
 public void Break()
 {
     Destroy(gameObject);
     BulletHit?.Invoke(this);
 }
コード例 #12
0
 internal void OnBulletHit()
 {
     BulletHit?.Invoke(id);
 }
コード例 #13
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            List <Bullet> bulletRemove = new List <Bullet>();

            foreach (Bullet bullets in Bullets.Children)
            {
                bullets.Update(gameTime);

                if (bullets.offScreen)
                {
                    bulletRemove.Add(bullets);
                }
            }
            List <Enemy> enemyRemove = new List <Enemy>();

            foreach (Enemy Enemies in Enemies.Children)
            {
                Enemies.Update(gameTime);

                foreach (Bullet BulletHit in Bullets.Children)
                {
                    if (BulletHit.CollidesWith(Enemies))
                    {
                        score.getScore = score.getScore + _scoreUp;
                        bulletRemove.Add(BulletHit);
                        enemyRemove.Add(Enemies);
                    }
                }
            }
            foreach (Enemy enemy in enemyRemove)
            {
                Enemies.Remove(enemy);
            }
            foreach (Bullet bullets in bulletRemove)
            {
                Bullets.Remove(bullets);
            }

            for (int i = Enemies.Children.Count; i < _amountOfEnemies; i++)
            {
                Enemies.Add(new Enemy());
            }

            if (_hit == true)
            {
                _frameCounter++;
            }
            foreach (Enemy EnemyHit in Enemies.Children)
            {
                if (EnemyHit.CollidesWith(thePlayer))
                {
                    if (_hit == false)
                    {
                        foreach (Health health in Health.Children)
                        {
                            if (_healthRemove == false)
                            {
                                KillList.Add(health);
                                _healthRemove = true;
                            }
                        }
                        _healthRemove = false;
                        _hit          = true;

                        thePlayer.HEALTH = thePlayer.HEALTH - _hpDown;
                    }
                }
            }
            if (_frameCounter >= 60)
            {
                _hit          = false;
                _frameCounter = 0;
            }
            foreach (Health health in Health.Children)
            {
            }

            foreach (var aObject in KillList.Children)
            {
                Health.Remove(aObject);
            }

            if (thePlayer.HEALTH <= 0)
            {
                GameEnvironment.GameStateManager.SwitchTo("GameOver");
                thePlayer.Reset();
                Enemies.Reset();
                Health.Reset();
                score.getScore   = 0;
                thePlayer.HEALTH = 3;
                for (int i = 0; i < _healtPoints; i++)
                {
                    Health.Add(new Health(new Vector2(150 - (i * _space), 10)));
                }
            }
        }
コード例 #14
0
ファイル: BulletHit.cs プロジェクト: wow4all/Scripts
    public void calculateDamage()
    {
        //Debug.Log("Hit " + hit.collider.gameObject.name);

        if (hit.collider.gameObject.Equals(shooter.gameObject))
        {
            return;
        }

        Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

        if (hit.transform.gameObject.GetComponent <Rigidbody>() != null)
        {
            hit.transform.gameObject.GetComponent <Rigidbody>().AddForce(hit.normal * -HitStrength);
        }
        if (hit.transform.tag == "Explosive")
        {
            if ((Detonator)hit.transform.gameObject.GetComponent("Detonator") != null)
            {
                Detonator target = (Detonator)hit.transform.gameObject.GetComponent("Detonator");
                try {
                    target.Explode();
                } catch (System.SystemException e) {
                    Debug.LogError("Detonator failed inside Weapon");
                    Debug.LogError(e.ToString());
                }
            }
            if (hit.transform.gameObject.GetComponent("AudioSource") != null)
            {
                AudioSource targetSound = (AudioSource)hit.transform.gameObject.GetComponent("AudioSource");
                targetSound.Play();
            }
            if (hit.transform.gameObject.GetComponent <ExplosiveDamage>() != null)
            {
                hit.transform.gameObject.GetComponent <ExplosiveDamage>().explode();
            }
        }
        else if (hit.transform.tag == "Combatant")
        {
            if (hit.transform.gameObject.GetComponent("AudioSource") != null)
            {
                AudioSource targetSound = (AudioSource)hit.transform.gameObject.GetComponent("AudioSource");
                targetSound.Play();
            }
            if (hit.transform.gameObject.GetComponent("EnemyHealth") != null)
            {
                EnemyHealth enemyHealth = (EnemyHealth)hit.transform.gameObject.GetComponent("EnemyHealth");
                enemyHealth.damageAsCombatant(Damage, shooter, DamageCause.Shot);
                if (debug)
                {
                    MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                }
            }
            if (hit.transform.gameObject.GetComponent <Health>() != null)
            {
                Health enemyHealth = hit.transform.gameObject.GetComponent <Health>();
                enemyHealth.Damage(Damage, DamageCause.Shot);
                if (debug)
                {
                    MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                }
            }
            if (hit.transform.FindChild("Camera") != null)
            {
                if (hit.transform.FindChild("Camera").gameObject.GetComponent <Health>() != null)
                {
                    Health enemyHealth = hit.transform.FindChild("Camera").gameObject.GetComponent <Health>();
                    enemyHealth.Damage(Damage, DamageCause.Shot);
                    if (debug)
                    {
                        MonoBehaviour.print("Dealt " + Damage.ToString() + " Damage to " + hit.transform.gameObject.name);
                    }
                }
            }
            GameObject newBlood = (GameObject)MonoBehaviour.Instantiate(BloodSpray, hit.point, hitRotation);
            newBlood.transform.parent = hit.transform;
            newBlood.transform.Translate(0, (float)0.05, 0);
        }
        else if (hit.transform.gameObject.GetComponent <ShatterableGlass>() != null)
        {
            ShatterableGlass pane = hit.transform.gameObject.GetComponent <ShatterableGlass>();
            pane.shoot(hit, HitStrength);
            if (debug)
            {
                MonoBehaviour.print("Shot glass pane " + pane.name);
            }
        }
        else if (hit.transform.gameObject.GetComponent <SplashingWater>() != null)
        {
            SplashingWater pane = hit.transform.gameObject.GetComponent <SplashingWater>();
            pane.Splash(hit.point);
            if (debug)
            {
                MonoBehaviour.print("Shot Water " + pane.name);
            }
        }
        else if (hit.transform.gameObject.GetComponent <PenetrableCover>() != null)
        {
            if (debug)
            {
                MonoBehaviour.print("Shot penetrable target " + hit.transform.gameObject.name);
            }
            BulletHit b = hit.transform.gameObject.GetComponent <PenetrableCover>().catchBullet(this);
            //this = hit.transform.gameObject.GetComponent<PenetrableCover>().catchBullet(this);

            b.calcHit();                     //This is what ccauses the refracted/reflected bullet to actualy start moving.
        }
        else
        {
            if (debug)
            {
                MonoBehaviour.print("Shot " + hit.transform.name);
            }


            GameObject newBulletHole = (GameObject)MonoBehaviour.Instantiate(BulletHole, hit.point, hitRotation);
            newBulletHole.transform.parent = hit.transform;
            newBulletHole.transform.Translate(0, (float)0.05, 0);
            hitRotation.x = hitRotation.x + 270;

            GameObject newDust = (GameObject)MonoBehaviour.Instantiate(DirtSpray, hit.point, hitRotation);
            newDust.transform.parent = hit.transform;
            newDust.transform.Translate(0, (float)0.05, 0);
        }
    }
コード例 #15
0
 private void Awake()
 {
     rb  = GetComponentInChildren <Rigidbody>();
     hit = GetComponentInChildren <BulletHit>();
 }
コード例 #16
0
ファイル: Weapon.cs プロジェクト: wow4all/Scripts
 /// <summary>
 /// generates a new BulletHit that can be used for calculating reflections and shots.
 /// </summary>
 /// <returns>
 /// The bullet hit generated.
 /// </returns>
 /// <param name='Hit'>
 /// The raycastHit to use.
 /// </param>
 /// <param name='shooter'>
 /// The Enemy that shot the gun.
 /// </param>
 public BulletHit generateHit(RaycastHit Hit, Enemy shooter)
 {
     BulletHit bh = new BulletHit();
     bh.BloodSpray = BloodSpray;
     bh.BulletHole = BulletHole;
     bh.caliber = ammoType;
     bh.Damage = Damage;
     bh.DirtSpray = DirtSpray;
     bh.hit = Hit;
     bh.HitStrength = HitStrength;
     bh.maxRange = Range;
     bh.origin = camera.transform.position;
     bh.shooter = shooter;
     return bh;
 }
コード例 #17
0
 private void Start()
 {
     rb  = GetComponent <Rigidbody>();
     hit = GetComponentInChildren <BulletHit>();
 }