Esempio n. 1
0
    /*
     *
     * Public functions
     *
     */

    public void TakeDamage(int damage)
    {
        int current = playerHealth.curHealth;

        Debug.Log(current);
        playerHealth.AdjustCurrentHealth(-damage);
        current -= damage;

        if (current >= 30 && burnParticles.isPlaying)
        {
            // playerHealth.curHealth = current;
            burnParticles.Stop();
        }

        if (current <= 20 && !burnParticles.isPlaying)
        {
            //playerHealth.curHealth = current;
            burnParticles.Play();
        }

        if (playerHealth.curHealth == 0 && !GameManagerSnow.isGamePaused())
        {
            //GameOver
            animator.SetBool("isMoving", false);
            animator.SetBool("isKilled", true);
            explodeParticles.Play();
            gameManager.FinishGame(SecondPlayer);
            soundManager.PlayDeath();
        }
        else
        {
            soundManager.PlayHurt();
        }
    }
    private void AttackPlayer()
    {
        Debug.Log("player hurt");
        PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");

        ph.AdjustCurrentHealth(weaponDamage);
    }
Esempio n. 3
0
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);         // defines the distance the player can hit the enemy

        Vector3 dir = (target.transform.position - transform.position).normalized;

        float direction = Vector3.Dot(dir, transform.forward);

        Debug.Log(distance);        // to measure distance in console for defining distances
        if (distance < 10)          // max distance the player can be from enemy to hit
        {
            if (direction > 0)      // makes sure player is facing enemy to hit


            {
                Animation[] anims = GetComponentsInChildren <Animation>();

                foreach (Animation anim in anims)
                {
                    anim.CrossFade("Att3");
                }
                PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
                eh.AdjustCurrentHealth(-5);                 // enemy loses 10 health for each attack it is hit by
            }
        }
    }
Esempio n. 4
0
    //Attack method for the enemy that brawls with the player close range
    private void MeleeAttack()
    {
        //To check how far the player is from the enemy
        float distance = Vector3.Distance(target.transform.position, transform.position);

        Vector3 dir = (target.transform.position - transform.position).normalized;

        float direction = Vector3.Dot(dir, transform.forward);

        //checker to see our distance from the enemy and direction
        //Debug.Log(distance);
        //Debug.Log(direction);

        if (distance <= 2)
        {
            if (direction > 0)
            {
                attackOn = true;
                PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");
                ph.AdjustCurrentHealth(-5);
            }
            else
            {
                //attackOn = false;
            }
        }
        else
        {
            attackOn = false;
        }
    }
Esempio n. 5
0
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);

        //set direction and move one unit forward
        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        //call new instance of Enemny health
        PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");

        //Debug.Log(distance);

        //should return between 1 and -1, 1 is in front, -1 is behind

        //Debug.Log(direction);


        if (distance <= 2.5f)
        {
            if (direction > 0)
            {
                eh.AdjustCurrentHealth(-10);
            }
        }
    }
 void OnCollisionEnter(Collision other)
 {
     if (other.gameObject.CompareTag("Player"))
     {
         PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");
         ph.AdjustCurrentHealth(+10);
         Destroy(this.gameObject);
     }
 }
Esempio n. 7
0
    /*
     *
     * Public functions
     *
     */

    public void TakeDamage(int damage)
    {
        playerHealth.AdjustCurrentHealth(-damage);
        if (playerHealth.curHealth <= 20 && !burnParticles.isPlaying)
        {
            burnParticles.Play();
        }

        if (playerHealth.curHealth == 0 && !GameManagerBoss.isGamePaused())
        {
            //GameOver
            animator.SetBool("isMoving", false);
            animator.SetBool("isKilled", true);
            explodeParticles.Play();
            gameManager.FinishGame(SecondPlayer);
            soundManager.PlayDeath();
        }
        else
        {
            soundManager.PlayHurt();
        }
    }
Esempio n. 8
0
    private void Attack()
    {
        float   distance  = Vector3.Distance(target.transform.position, transform.position);
        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        if (distance < 5.0f)
        {
            if (direction > 0)
            {
                PlayerHealth ph = (PlayerHealth)target.GetComponent("PlayerHealth");
                ph.AdjustCurrentHealth(-10);
            }
        }
    }
Esempio n. 9
0
    private void Attack()
    {
        float distance = Vector3.Distance(target.transform.position, transform.position);

        Vector3 dir = (target.transform.position - transform.position).normalized;

        float direction = Vector3.Dot(dir, transform.forward);

        if (distance < 2.5f && direction > 0)
        {
            PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
            eh.AdjustCurrentHealth(-10);
            attackTimer = coolDown;
        }
    }
Esempio n. 10
0
    // Attack
    private void Attack()
    {
        // distance between the target and the player
        float distance = Vector3.Distance(target.transform.position, transform.position);

        // check where enemy is wrt the player
        // dot product returns value between 1 and -1. 1 means enemy is in front of us, -1 he's to the back
        Vector3 dir       = (target.transform.position - transform.position).normalized;
        float   direction = Vector3.Dot(dir, transform.forward);

        //Debug.Log(direction);


        if (distance < 2.5f)         // check if close enough for attack to hit
        {
            if (direction > 0)       // check whether enemy is in front of us
            {
                // ref to EnemyHealth script of target and do damage
                PlayerHealth eh = (PlayerHealth)target.GetComponent("PlayerHealth");
                eh.AdjustCurrentHealth(-10);
            }
        }
    }
Esempio n. 11
0
    // Update is called once per frame
    void Update()
    {
        enemyObjects = GameObject.FindGameObjectsWithTag("Player2");

        if (enemyObjects.Length != 0)
        {
            GameObject        constVar = GameObject.FindGameObjectWithTag("Constant");
            StoredInformation stored   = constVar.GetComponent <StoredInformation>();
            counter = stored.EnemyBattlePosition;

            EnemyAttack  enAttack;
            GameObject[] obj = GameObject.FindGameObjectsWithTag("Enemy2");
            enAttack = obj[counter].GetComponent <EnemyAttack>();

            enemyObjects = GameObject.FindGameObjectsWithTag("Player2");


            fighterNumber = Random.Range(0, enemyObjects.Length);
            EnemyTarget   = enemyObjects[fighterNumber];
            if (EnemyTarget == null)
            {
                EnemyTarget = enemyObjects[fighterNumber + 1];
            }
            if (myTransform == null)
            {
                myTransform = transform;
            }

            EnemyTimeSimulation enemTimeScript = obj[counter].GetComponent <EnemyTimeSimulation>();
            if (enemTimeScript.timeToAttack1 > 99)
            {
                this.attempt = true;

                if (attempt)
                {
                    Quaternion rot;

                    rot = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(EnemyTarget.transform.position - myTransform.position), 6 * Time.deltaTime);
                    myTransform.rotation  = rot;
                    myTransform           = GameObject.FindGameObjectWithTag("Enemy2").transform;
                    myTransform.position += new Vector3(myTransform.forward.x * 6 * Time.deltaTime,
                                                        0,
                                                        myTransform.forward.z * 6 * Time.deltaTime);
                    if (obj[0].name == "CaveWorm(Clone)")
                    {
                        animation.Play("Walk");
                    }
                    else
                    {
                        animation.Play("walk");
                    }
                }

                if ((Vector3.Distance(myTransform.position, EnemyTarget.transform.position) < 1) && (attempt != false))
                {
                    initialiseParticles = new GameObject();
                    EnemyTarget         = enemyObjects[fighterNumber];
                    Transform enemyTransform = EnemyTarget.transform;
                    if (obj[0].name == "CaveWorm(Clone)")
                    {
                        animation.Play("Attack");
                    }

                    if (obj[0].name == "Monster2Prefab(Clone)")
                    {
                        animation.Play("bitchslap");
                    }

                    if (obj[0].name == "spider(Clone)")
                    {
                        animation.Play("attack1");
                    }

                    PlayerHealth attackEnemy = EnemyTarget.GetComponent <PlayerHealth>();

                    attackType = Random.Range(0, 5);
                    if (attackType == 1)
                    {
                        attackEnemy.AdjustCurrentHealth((int)(stored._attackValue[0] / stored._defenceValue[0]), fighterNumber);
                    }
                    if (attackType == 2)
                    {
                        attackEnemy.AdjustCurrentHealth((int)(stored._attackValue[1] / stored._defenceValue[1]), fighterNumber);
                        initialiseParticles      = Instantiate(particles[0], EnemyTarget.transform.position, Quaternion.identity) as GameObject;
                        initialiseParticles.name = "Fire";
                    }
                    if (attackType == 3)
                    {
                        attackEnemy.AdjustCurrentHealth((int)(stored._attackValue[2] / stored._defenceValue[1]), fighterNumber);
                        initialiseParticles      = Instantiate(particles[1], EnemyTarget.transform.position, Quaternion.identity) as GameObject;
                        initialiseParticles.name = "Ice";
                    }
                    if (attackType == 4)
                    {
                        attackEnemy.AdjustCurrentHealth((int)(stored._attackValue[3] / stored._defenceValue[1]), fighterNumber);
                        initialiseParticles      = Instantiate(particles[2], EnemyTarget.transform.position, Quaternion.identity) as GameObject;
                        initialiseParticles.name = "Lightning";
                    }
                    if (Vector3.Distance(myTransform.position, EnemyTarget.transform.position) <= 1)
                    {
                        this.attempt = false;
                    }
                    if (enAttack.attempt == false)
                    {
                        GameObject[] atemptingChange = GameObject.FindGameObjectsWithTag("EnemyBattle");
                        obj[counter].transform.position = atemptingChange[counter].transform.position;
                        enemTimeScript.timeToAttack1    = 0;
                        this.attempt = false;
                        enemTimeScript.timeToAttack = 0;
                        if (obj[0].name == "CaveWorm(Clone)")
                        {
                            animation.Play("Idle");
                        }
                        if ((obj[0].name == "spider(Clone)") || (obj[0].name == "Monster2Prefab(Clone)"))
                        {
                            animation.Play("idle");
                        }
                    }
                }
            }
        }
    }