示例#1
0
    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        if (hit.collider.GetComponent <AmmoCrate>() != null)                                                                    //Collect ammo crate
        {
            AmmoCrate ammoCrate = hit.collider.GetComponent <AmmoCrate>();
            ammo += ammoCrate.ammo;

            Destroy(ammoCrate.gameObject);
        }
        else if (hit.collider.GetComponent <Enemy>() != null)
        {
            if (isHurt == false)
            {
                {
                    Enemy enemy = hit.collider.GetComponent <Enemy>();                                                            //Enemy damage
                    health -= enemy.damage;

                    isHurt = true;

                    Vector3 hurtDirectrion     = (transform.position - enemy.transform.position).normalized;                      //Perform the knockback effect
                    Vector3 hurtDirection      = default;
                    Vector3 KnockbackDirection = (hurtDirection + Vector3.up).normalized;
                    GetComponent <ForceReceiver> ().AddForce(KnockbackDirection, knockbackForce);

                    StartCoroutine(HurtRoutine());
                }
            }
        }
    }
示例#2
0
    void FireShotgun()
    {
        for (int i = 0; i < shotgunPellets; i++)
        {
            Vector3 temp = pistolFirePt.right;
            temp.y += Random.Range(-0.3f, 0.3f);
            RaycastHit2D hitInfo = Physics2D.Raycast(shotgunFirePt.position, temp);
            if (hitInfo)
            {
                Enemy     enemy = hitInfo.transform.GetComponent <Enemy>();
                AmmoCrate crate = hitInfo.transform.GetComponent <AmmoCrate>();
                if (enemy != null && crate == null)
                {
                    enemy.TakeDamage((int)(shotgun_base_DMG * damage_mult));
                }
                else if (enemy == null && crate != null)
                {
                    crate.DamageCrate((int)(shotgun_base_DMG * damage_mult));
                }
                DrawLine(shotgunFirePt.position, hitInfo.point, Color.white, 0.05f);

                GameObject new_hit = (GameObject)Instantiate(impact_effect, hitInfo.point, Quaternion.identity);
                Destroy(new_hit, 0.267f);
            }
            else
            {
                DrawLine(shotgunFirePt.position, shotgunFirePt.position + temp * 100, Color.white, 0.05f);
            }
        }
    }
示例#3
0
    // check for collision
    void OnTriggerEnter(Collider otherCollider)
    {
        if (otherCollider.GetComponent <AmmoCrate>() != null)
        {
            // collect ammoCreate.
            AmmoCrate ammoCrate = otherCollider.GetComponent <AmmoCrate>();
            ammo += ammoCrate.ammo;
            Destroy(ammoCrate.gameObject);
        }
        else if (otherCollider.GetComponent <HealthCrate>() != null)
        {
            // collect healthCreate.
            HealthCrate healthCrate = otherCollider.GetComponent <HealthCrate>();
            health += healthCrate.health;
            Destroy(healthCrate.gameObject);
        }
        if (!isHurt)
        {
            GameObject hazard = null;
            if (otherCollider.GetComponent <Enemy>() != null)
            {
                Enemy enemy = otherCollider.GetComponent <Enemy>();
                if (enemy.kill == false)
                {
                    hazard  = enemy.gameObject;
                    health -= enemy.damage;
                }
            }
            else if (otherCollider.GetComponent <Bullet>() != null)
            {
                Bullet bullet = otherCollider.GetComponent <Bullet>();
                if (bullet.ShotByPlayer == false)
                {
                    hazard  = bullet.gameObject;
                    health -= bullet.damage;
                    bullet.gameObject.SetActive(false);
                }
            }
            if (hazard != null)
            {
                isHurt = true;
                // knock back effect
                Vector3 hurtDirection      = (transform.position - hazard.transform.position).normalized;
                Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized;

                GetComponent <ForceReceiver>().AddForce(knockbackDirection, knockBackForce);
                GetComponent <Rigidbody>().AddForce(knockbackDirection * knockBackForce);
                StartCoroutine(HurtRoutine());
            }
            if (health <= 0)
            {
                if (killed == false)
                {
                    killed = true;
                    OnKill();
                }
            }
        }
    }
示例#4
0
 public AmmoDropEvent(Texture2D texture, Vector3 location, Scene scene) : base(false, true)
 {
     this.rep       = new Sprite(texture);
     this.ammoCrate = new AmmoCrate(rep);
     this.scene     = scene;
     ammoCrate.SetPosition(new Vector2(location.X, location.Y - 20));
     ammoCrate.AmmoCrateCollectEventList.EventList.Add(new AmmoCrateCollectEvent(scene, ammoCrate));
     scene.RegisterObject(ammoCrate);
 }
    private void OnTriggerEnter(Collider other)
    {
        AmmoCrate ammoCrate = other.gameObject.GetComponent <AmmoCrate>();

        if (ammoCrate)
        {
            ReplenishAmmo(ammoCrate);
        }
    }
示例#6
0
    //Check for collisions
    void OnTriggerEnter(Collider otherCollider)
    {
        if (otherCollider.GetComponent <AmmoCrate>() != null)
        {
            Debug.Log("Ammo crate collision");
            //Ammo crate collision
            AmmoCrate ammoCrate = otherCollider.GetComponent <AmmoCrate>();
            player.currentTotalAmmo += ammoCrate.ammo;

            Destroy(ammoCrate.gameObject);
        }
    }
 void ReplenishAmmo(AmmoCrate ammoCrate)
 {
     foreach (Weapon weapon in weaponController.weapons)
     {
         if (weapon.weaponType == ammoCrate.type)
         {
             weapon.ammoCount = weapon.ammoMax;
             Destroy(gameObject);
             return;
         }
     }
 }
示例#8
0
        public void Execute(long currentTimeMs, List <Actor> touchedActors)
        {
            DefaultCharacter currentCharacter = (DefaultCharacter)character;

            if (currentCharacter == null)
            {
                return;
            }

            if ((currentTimeMs - timeLastExecuted) < cooldown)
            {
                return;
            }

            bool isFacingRight = physics.IsFacingRight();

            if (currentCharacter.InvTreasure == null)
            {
                foreach (Actor actor in touchedActors)
                {
                    Treasure treasure = actor as Treasure;
                    if (treasure != null)
                    {
                        treasure.CharacterCollect(character);
                    }

                    AmmoCrate ammoCrate = actor as AmmoCrate;
                    if (ammoCrate != null)
                    {
                        ammoCrate.CharacterCollect(character);
                    }

                    Trap trap = actor as Trap;
                    if (trap != null)
                    {
                        trap.CharacterCollect(character);
                    }
                }
            }


            timeLastExecuted = currentTimeMs;
        }
示例#9
0
文件: Player.cs 项目: arturfil/FPS-3D
    // Check for collision with Ammo crate;
    void OnTriggerEnter(Collider otherCollider)
    {
        if (otherCollider.GetComponent <AmmoCrate>() != null)
        {
            // Check for Collect ammo crate
            AmmoCrate ammoCrate = otherCollider.GetComponent <AmmoCrate>();
            ammo += ammoCrate.ammo;
            Destroy(ammoCrate.gameObject);
        }

        if (isHurt == false)
        {
            GameObject hazard = null;

            if (otherCollider.GetComponent <Enemy>() != null)
            {
                // Check for collisions with enemies
                Enemy enemy = otherCollider.GetComponent <Enemy>();
                hazard  = enemy.gameObject;
                health -= enemy.damage;
            }
            else if (otherCollider.GetComponent <Bullet>() != null)
            {
                Bullet bullet = otherCollider.GetComponent <Bullet>();
                if (bullet.ShotByPlayer == false)
                {
                    hazard  = bullet.gameObject;
                    health -= bullet.damage;
                    bullet.gameObject.SetActive(false);
                }
            }

            if (hazard != null)
            {
                isHurt = true;
                // Perform the knockback effect
                Vector3 hurtDirection      = (transform.position - hazard.transform.position).normalized;
                Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized;
                GetComponent <ForceReceiver>().AddForce(knockbackDirection, knockbackForce);
                StartCoroutine(HurtRoutine());
            }
        }
    }
示例#10
0
    // check for collisions
    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        AmmoCrate ammoCrate = hit.collider.gameObject.GetComponent <AmmoCrate>();
        Enemy     enemy     = hit.collider.gameObject.GetComponent <Enemy>();

        if (ammoCrate != null)
        {
            ammo += ammoCrate.ammo;
            Destroy(ammoCrate.gameObject);
        }
        else if (enemy != null)
        {
            if (!isHurt)
            {
                health -= enemy.damage;
                isHurt  = true;
                Vector3 hurtDirection      = (transform.position - enemy.transform.position).normalized;
                Vector3 knockBackDirection = hurtDirection + Vector3.up;
                GetComponent <Rigidbody>().AddForce(knockBackDirection * knockbackForce);
                StartCoroutine(HurtRoutine());
            }
        }
    }
示例#11
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Area"))
        {
            if (area != null && area.gameObject == other.gameObject)
            {
                return;
            }

            area = other.GetComponent <Area>();
            area.Enter();
        }

        if (other.CompareTag("TriggerDeath"))
        {
            Death();
        }

        if (other.CompareTag("AmmoCrate"))
        {
            AmmoCrate ammoCrate = other.GetComponent <AmmoCrate>();

            if (ammoCrate != null)
            {
                int leftOverAmmo = GiveAmmo(ammoCrate.ammoType, ammoCrate.ammo);

                if (leftOverAmmo <= 0)
                {
                    Destroy(ammoCrate.gameObject);
                }
                else
                {
                    ammoCrate.ammo = leftOverAmmo;
                }
            }
        }
    }
示例#12
0
    void OnTriggerEnter(Collider otherCollider)
    {
        if (otherCollider.GetComponent <AmmoCrate>() != null)
        {
            AmmoCrate ammoCrate = otherCollider.GetComponent <AmmoCrate>();
            ammo += ammoCrate.ammo;

            Destroy(ammoCrate.gameObject);
        }
        else if (otherCollider.GetComponent <HealthCrate>() != null)
        {
            HealthCrate healthCrate = otherCollider.GetComponent <HealthCrate>();
            health += healthCrate.health;

            Destroy(healthCrate.gameObject);
        }

        if (!isHurt)
        {
            GameObject hazard = null;
            if (otherCollider.GetComponent <Enemy>() != null)
            {
                Debug.Log("Collide with enemy");
                Enemy enemy = otherCollider.GetComponent <Enemy>();
                if (!enemy.Killed)
                {
                    hazard  = enemy.gameObject;
                    health -= enemy.damage;
                }
            }
            else if (otherCollider.GetComponent <Bullet>() != null)
            {
                Bullet bullet = otherCollider.GetComponent <Bullet>();
                if (!bullet.ShotByPlayer)
                {
                    Debug.Log("Collide with bullet");
                    hazard  = bullet.gameObject;
                    health -= bullet.damage;

                    bullet.gameObject.SetActive(false);
                }
            }

            if (hazard != null)
            {
                isHurt = true;

                Vector3 hurtDirection      = (transform.position - hazard.transform.position).normalized;
                Vector3 knockbackDirection = (hurtDirection + Vector3.up).normalized;
                GetComponent <ForceReceiver>().AddForce(knockbackDirection, knockbackForce);

                StartCoroutine(HurtRoutine());
            }
        }

        if (health <= 0 && !killed)
        {
            killed = true;
            OnKill();
        }
    }
示例#13
0
 public AmmoCrateCollectEvent(Scene scene, AmmoCrate ammoCrate) : base(false, true)
 {
     this.scene     = scene;
     this.ammoCrate = ammoCrate;
 }