Example #1
0
    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.tag == "WindWalker")
        {
            healthScript.DamageHealth(enemyDmg);
        }
        if (collider.gameObject.tag == "Sage")
        {
            healthScript.DamageHealth(enemyDmg);
        }
        if (collider.gameObject.tag == "Warrior")
        {
            healthScript.DamageHealth(enemyDmg);
        }
        if (collider.gameObject.tag == "Ninja")
        {
            healthScript.DamageHealth(enemyDmg);
        }

        if (collider.gameObject.tag == "Projectile")
        {
            enemyHealth.DamageHealth(rangedPlayerDamage);
            Destroy(collider.gameObject);
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (health.GetHealth() < 200)
     {
         health.DamageHealth(-500);
     }
 }
Example #3
0
 public void Hurt(int Attack)
 {
     _lastHit = Time.time;
     // Reduce the number of hit points by one.
     if (_enemyShield.IsShieldActive())
     {
         int extraDamage = _enemyShield.DamageShield(Attack);
         if (extraDamage != 0)
         {
             _enemyHealth.DamageHealthValue(extraDamage);
         }
     }
     else
     {
         _enemyHealth.DamageHealth(Attack);
     }
 }
Example #4
0
    // Ray cast mechanic for shooting
    void Shooting()
    {
        // checks if the player is in the alive state which means the player can shoot
        if (health.playerState == PlayerHealth.PlayerState.ALIVE)
        {
            // checks if the controller is connected
            if (xboxController.useController == true)
            {
                // plays the counter
                counter += Time.deltaTime;
                // checks if the player is alive
                if (health.currentHealth > 0)
                {
                    // if the player presses the right trigger
                    if (XCI.GetAxis(XboxAxis.RightTrigger, xboxController.controller) > 0.1f)
                    {
                        // the player will shoot
                        shotTimer += Time.deltaTime;

                        if (counter > delay)
                        {
                            // plays muzzle flash and bullet casing particles
                            muzzleFlash.Play();
                            bulletCasing.Play();

                            // bullets
                            // instantiates bullets as long as the player is holding down the right trigger
                            GameObject bullet = Instantiate(particleProjectile, transform.position, chunkRotation.transform.rotation);
                            // resets the cvounter whenever bullet is copied
                            counter = 0f;
                            // plays the shooting animation while the gun is shooting
                            anim.SetBool("IsAttacking", true);

                            // play audio clips
                            if (shotTimer >= shotInterval)
                            {
                                audioSource.pitch = Random.Range(minPitch, maxPitch);
                                audioSource.PlayOneShot(gunShots[Random.Range(0, gunShots.Count)]);
                                audioSource.PlayOneShot(shellCasings[Random.Range(0, shellCasings.Count)], shellVolume);
                            }

                            // Ray cast mechanic
                            RaycastHit hit;
                            Ray        rayCast = new Ray(transform.position, transform.forward);
                            if (Physics.Raycast(rayCast, out hit, range, layerMask))
                            {
                                // enemy health damaged
                                target = hit.transform.GetComponent <EnemyHealth>();
                                if (target != null)
                                {
                                    // damage to the target
                                    target.DamageHealth(damageToGive);
                                    // camera shake when shooting enemies
                                    cameraController.ShakeCamera();
                                    // instantiates blood splatter on enemies that are hit
                                    GameObject impact = Instantiate(bloodEffect, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
                                    Destroy(impact, 0.5f);
                                }
                                // destructable pots
                                DestructableObjects obj = hit.transform.GetComponent <DestructableObjects>();
                                if (obj != null)
                                {
                                    obj.ObjectDamage(damageToGive);
                                    audioSource.pitch = Random.Range(minPitch, maxPitch);
                                    audioSource.PlayOneShot(bulletImpact[Random.Range(0, bulletImpact.Count)]);
                                    // instantiates bullet holes when destructables are shot at
                                    holes = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
                                    Destroy(holes, 0.2f);
                                    Debug.DrawLine(transform.position, hit.point, Color.red);
                                }
                            }
                        }
                    }
                    // if player releases the right trigger
                    else if (XCI.GetAxis(XboxAxis.RightTrigger, xboxController.controller) < 0.1)
                    {
                        // stop all particle effects
                        muzzleFlash.Stop();
                        bulletCasing.Stop();
                        shotTimer = 0;
                        // stop anaimation
                        anim.SetBool("IsAttacking", false);
                    }
                }
            }
            // if the player is in revive or dead state make sure the controller is off and doesnt allow the player to shoot
            else if (health.playerState == PlayerHealth.PlayerState.REVIVE && health.playerState == PlayerHealth.PlayerState.DEAD)
            {
                xboxController.useController = false;
            }
        }
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        switch (state)
        {
        case E_STATE.NORMAL:
            //Disable fire effect here?
            break;

        case E_STATE.IGNITED:
            //Mabye display some fire effect here?
            health.DamageHealth(fireDamageOverTime * Time.deltaTime);
            fireTime -= Time.deltaTime;
            //Enemy is no longer on fire
            if (fireTime <= 0.0f)
            {
                state = E_STATE.NORMAL;
            }
            break;
        }

        //Delayed death, use the dead() method for anything needing to happen on kill
        if (!alive)
        {
            deadTimer -= Time.deltaTime;
            if (deadTimer <= 0.0f)
            {
                spawner.Despawn(gameObject);
            }

            renderer.material.SetFloat("Dissolve_Value", (deadTimer * -1.0f) + 1.0f);
            acceleration = Vector3.zero;
            velocity     = Vector3.zero;
            return;
        }

        //Sound
        groanTimer -= Time.deltaTime;
        if (groanTimer <= 0.0f)
        {
            //Randomize the pitch
            audio.pitch = originalPitch + (Random.Range(-1.0f, 1.0f) * pitchVariance);

            //Play a sound at random
            if (Random.value >= 0.5f)
            {
                audio.PlayOneShot(groan1);
            }
            else
            {
                audio.PlayOneShot(groan2);
            }

            //Countdown till next groan
            groanTimer = groanDelay + (Random.Range(-1.0f, 1.0f) * groanVariance);
        }

        //If we have no path get one
        if (path == -1)
        {
            attackLocked = false;
            if (p1HP.playerState == PlayerHealth.PlayerState.ALIVE)
            {
                path = 0;
            }
            else if (p2HP.playerState == PlayerHealth.PlayerState.ALIVE)
            {
                path = 1;
            }
            else
            {
                return;
            }
        }

        //Debug.Log(path);
        //Just incase
        if (path == 0 && p1HP.playerState != PlayerHealth.PlayerState.ALIVE)
        {
            path     = -1;
            engaging = false;
        }
        else if (path == 1 && p2HP.playerState != PlayerHealth.PlayerState.ALIVE)
        {
            path     = -1;
            engaging = false;
        }

        //Cycle through all behaviours or attack
        if (engaging) //Attack
        {
            if (target == null)
            {
                engaging    = false;
                attackTimer = 0.0f;
                attackRecov = 0.0f;
                return;
            }
            //Move directly towards our target
            acceleration = target.transform.position - transform.position;

            attackTimer -= Time.deltaTime;
            if (attackLocked)
            {
                anim.SetBool("IsAttacking", true);
                if (attackTimer <= 0.0f && attackRecov <= 0.0f)
                {
                    Attack();
                    //Allow movement and rotation again
                    attackLocked = false;
                    //Set the time for cooldown between attacks
                    attackRecov = attackRate;
                }
            }
            else
            {
                attackRecov -= Time.deltaTime;
            }
        }
        else //Behaviours
        {
            anim.SetBool("IsAttacking", false);
            //Deadlock prevention!
            attackLocked = false;

            acceleration = Vector3.zero;
            foreach (BaseBehaviour b in behaviours)
            {
                acceleration += b.Update() * b.weight;
            }
        }
        //No up velocity
        acceleration.y = 0.0f;
        //Normalize it and multiply it by our speed
        acceleration.Normalize();
        acceleration *= movementSpeed;

        //Prevent movement while attacking ------
        if (attackLocked)
        {
            acceleration = Vector3.zero;
            velocity     = Vector3.zero;
        }

        velocity += acceleration / mass;
        velocity *= drag;

        //rotate towards where we are going
        if (velocity != Vector3.zero)
        {
            anim.SetBool("IsMoving", true);
            transform.localRotation = Quaternion.LookRotation(velocity);
            //transform.rotation.SetFromToRotation(Vector3.zero, velocity);
            action = E_ACTION.MOVE;
        }
        else
        {
            anim.SetBool("IsMoving", false);
        }

        //Cap max velocity
        if (velocity.magnitude > movementSpeed)
        {
            velocity = Vector3.Normalize(velocity) * movementSpeed;
        }

        //Anchor the enemy to the floor (rigidbody raycast fix)
        transform.position = new Vector3(transform.position.x, 0.0f, transform.position.z);
    }