Ejemplo n.º 1
0
    private bool IsGrounded()
    {
        if (rb2d.velocity.y <= 0)
        {
            foreach (Transform point in groundPoints)
            {
                Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, whatIsGround);

                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].gameObject != gameObject)
                    {
                        MyAnimator.ResetTrigger("jump");
                        MyAnimator.SetBool("land", false);
                        if (colliders[i].tag == "Platform")
                        {
                            transform.parent = colliders[i].gameObject.transform;
                        }

                        return(true);
                    }
                }
            }
        }
        transform.parent = null;
        return(false);
    }
Ejemplo n.º 2
0
 public override void Death()
 {
     MyAnimator.ResetTrigger("die");
     MyAnimator.SetTrigger("idle");
     health             = 30;
     transform.position = startPos;
 }
Ejemplo n.º 3
0
 public override void Death()
 {
     MyAnimator.ResetTrigger("die");
     MyAnimator.SetTrigger("idle");
     healthStat.CurrentVal = healthStat.MaxValue;
     transform.position    = startPos;
 }
Ejemplo n.º 4
0
    private bool IsGrounded(Rigidbody2D MyRigidbody)
    {
        if (MyRigidbody.velocity.y <= 0.2)
        {
            //MyRigidbody.velocity += Vector2.up * Physics2D.gravity.y * (fallMultiplier - 1) * Time.deltaTime;
            foreach (Transform point in groundPoints)
            {
                //Gets the colliders on the player's feet
                Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundRadius, groundMask);

                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].gameObject != gameObject && (colliders[i].gameObject.CompareTag("Floor") || ((this.gameObject.layer == 9 && colliders[i].gameObject.layer == 8) || (this.gameObject.layer == 8 && colliders[i].gameObject.layer == 9))))
                    {
                        //If the colliders collide with something else than the player, then the players is grounded
                        canJump   = true;
                        isJumping = false;
                        MyAnimator.ResetTrigger("Jump");
                        if (MyAnimator.GetBool("Land"))
                        {
                            MyAnimator.SetBool("Land", false);
                            AudioManager.instance.Play(gameObject.name + "Land");
                            StartCoroutine("LandEffect");
                        }
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 5
0
    private IEnumerator DamagePlayer()
    {
        health--;
        AudioManager.instance.Play("Damage");
        UIManager.UImanager.TakeDamageUI(health, this.name);

        canMove     = false;
        rb.velocity = new Vector2(0, 0);

        MyAnimator.SetTrigger("Damage");
        MyAnimator.ResetTrigger("Damage");

        shake.CamShake();
        if (this.playerName == "One" && !IsDead())
        {
            GamePad.SetVibration(PlayerIndex.One, 0.1f, 0.1f);
            yield return(new WaitForSeconds(0.7f));

            GamePad.SetVibration(PlayerIndex.One, 0, 0);
        }

        if (this.playerName == "Two" && !IsDead())
        {
            GamePad.SetVibration(PlayerIndex.Two, 0.1f, 0.1f);
            yield return(new WaitForSeconds(0.7f));

            GamePad.SetVibration(PlayerIndex.Two, 0, 0);
        }
    }
Ejemplo n.º 6
0
    public override void Death()
    {
        //To respawn the enemy
        MyAnimator.ResetTrigger("die");
        MyAnimator.SetTrigger("idle");
        if (scene.name == "Level3" || scene.name == "Level2")
        {
            Player.score += 10;
        }
        if (scene.name == "Level4" || scene.name == "Level5" || scene.name == "Level6")
        {
            if (GameControl.control.patent2 == 1)
            {
                Player.score += 10;
            }
        }

        if (scene.name == "Level7" || scene.name == "Level8" || scene.name == "Level9")
        {
            if (GameControl.control.patent3 == 1)
            {
                Player.score += 10;
            }
        }


        GameControl.control.coins += 20;
        //To respawn
        //transform.position = startPos;
        //health = 10;


        //To destroy the enemy
        Destroy(gameObject);
    }
Ejemplo n.º 7
0
/// <summary>
/// Death and Respawn
/// </summary>
    public override void Death()
    {
        MyRigidbody.velocity = Vector2.zero;
        MyAnimator.SetTrigger("idle");
        MyAnimator.ResetTrigger("death");
        health             = 30;
        transform.position = startPos;
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
Ejemplo n.º 8
0
 public override void Death()
 {
     dropItem = true;
     MyAnimator.ResetTrigger("die");
     MyAnimator.ResetTrigger("puffSpawn");
     MyAnimator.SetTrigger("idle");
     health.CurrentVal  = health.MaxVal;
     transform.position = starPos;
 }
Ejemplo n.º 9
0
 public override void Death()
 {
     dropItem = true;
     MyAnimator.ResetTrigger("die");
     MyAnimator.SetTrigger("idle");
     healthStat.CurrentVal = healthStat.MaxVal;
     transform.position    = startPos;
     healthCanvas.enabled  = false;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Removes the enemy from the game
 /// </summary>
 public override void Death()
 {
     //   Destroy(gameObject);
     dropItem = true;
     MyAnimator.ResetTrigger("Die");
     MyAnimator.SetTrigger("Idle");
     healthStat.CurrentVal = healthStat.MaxVal;
     transform.position    = startPos;
     healthCanvas.enabled  = false;
 }
Ejemplo n.º 11
0
 public override void Death()
 {
     MyAnimator.SetTrigger("idle");
     MyAnimator.ResetTrigger("die");
     Destroy(gameObject);
     if (this.tag == "boss")
     {
         new WaitForSeconds(5f);
         SceneManager.LoadScene("StitchBoy");
     }
 }
Ejemplo n.º 12
0
 public override void Death()   // multiple death options either destroy or respawn
 {
     //THIS WILL RESPAWN ENEMY (Change times in Enemy death animator)
     MyAnimator.SetTrigger("Idle");
     MyAnimator.ResetTrigger("Death");
     health             = enemyStartHealth;
     transform.position = startPos;
     Target             = null;
     // this will destroy this enemy game object upon death NO RESPAWN
     //  Destroy(gameObject);
 }
Ejemplo n.º 13
0
    private void HandleMovement(float h)
    {
        //Debug.Log("is in HandleMovement");
        if (IsButterfly || IsClimbing)
        {
            //Debug.Log("is a butterfly trying to move");
            //butterfly flight
            float moveHorizontal = Input.GetAxis("Horizontal") * (maxFlightSpeed + 3);
            float moveVertical   = Input.GetAxis("Vertical") * maxFlightSpeed;

            Vector2     movement = new Vector2(moveHorizontal, moveVertical);
            Rigidbody2D rig      = GetComponent <Rigidbody2D>();
            rig.AddForce(movement);
        }
        else
        {
            //normal movement and stuff
            if (MyRb2d.velocity.y < 0)
            {
                MyAnimator.SetBool("fall", true);
            }
            if (OnGround || airControl)
            {
                if (Input.GetKey(KeyCode.LeftShift))
                {
                    h *= 2;
                    MyAnimator.SetBool("run", true);
                    MyAnimator.SetTrigger("startRun");
                }
                //if (Input.GetKeyUp(KeyCode.LeftShift))
                else
                {
                    MyAnimator.SetBool("run", false);
                    MyAnimator.ResetTrigger("startRun");
                }
                MyRb2d.velocity = new Vector2(h * speed, MyRb2d.velocity.y);
            }
            if (Jumping && MyRb2d.velocity.y == 0)
            {
                MyRb2d.AddForce(new Vector2(0, jumpForce));
            }
            MyAnimator.SetFloat("walkSpeed", Mathf.Abs(h));

            /*
             * if (isGrounded && jumping)
             * {
             *  isGrounded = false;
             *  rb2d.AddForce(new Vector2(0, jumpForce));
             *  animator.SetTrigger("jump");
             * }
             */
        }
    }
Ejemplo n.º 14
0
    void Update()
    {
        if (kills == 20)
        {
            SceneManager.LoadScene("Finsher", LoadSceneMode.Single);
        }
        HandleInput();

        if (health <= 0)
        {
            Dead = true;
        }
        else
        {
            Dead = false;
        }

        if (Attacking)
        {
            if (AttackTimer > 0)
            {
                AttackTimer -= Time.deltaTime;
            }
            else
            {
                Attacking             = false;
                AttackTrigger.enabled = false;
            }
        }

        if (health <= 0)
        {
            DeadTimer += Time.deltaTime;
            if (DeadTimer >= DeadCD)
            {
                transform.position = ReSpawn;
                MyAnimator.ResetTrigger("Die");
                //MyAnimator.ResetTrigger ("Die");
                health = 100;
                Dead   = false;
                MyAnimator.SetTrigger("Respawn");
                MyAnimator.ResetTrigger("Respawn");
                MyAnimator.SetTrigger("Respawn");
            }
        }

        CheckIfDead();

        HealthBarUpadte();
    }
    private void PlayerMovement(float move)
    {
        if (MyRigidbody.velocity.y < 0.1f)
        {
            MyAnimator.SetBool("land", true);
            MyRigidbody.gravityScale = 20f;
        }

        if (OnGround || airControl)
        {
            MyRigidbody.velocity = new Vector2(move * maxSpeed, MyRigidbody.velocity.y);
        }

        if (jump && MyRigidbody.velocity.y == 0)
        {
            MyAnimator.SetTrigger("jump");
            playerSound.clip = jumpSound;
            playerSound.Play();
            //MyRigidbody.AddForce (new Vector2 (0, jumpForce),ForceMode2D.Force);
            MyRigidbody.velocity = new Vector3(0, jumpTemp, 0);
        }

        if (OnGround)
        {
            MyRigidbody.gravityScale = 11f;
            MyAnimator.SetBool("land", false);
            MyAnimator.ResetTrigger("jump");
            jump = false;
        }

        if (!jump)
        {
            MyAnimator.SetFloat("speed", Mathf.Abs(move));
        }

        if (dropDown)
        {
            gameObject.layer = 14;
            StartCoroutine(DropDownAvail());
        }

        if (!dropDown)
        {
            gameObject.layer = 8;
        }
    }
Ejemplo n.º 16
0
 /// <summary>
 /// if the AI is not moving
 /// </summary>
 public override void Idle()
 {
     if (isIdle)
     {
         MyAnimator.SetBool("isWalking", false);
         idleDuration = UnityEngine.Random.Range(1, 10); // using UnityEngine's random function
         MyAnimator.SetTrigger("idleTurning");
         idleTimer += Time.deltaTime;
         if (idleTimer >= idleDuration)
         {
             isIdle    = false;
             isWalking = true;
             MyAnimator.ResetTrigger("idleTurning");
             MyAnimator.SetBool("isWalking", true);
         }
     }
 }
Ejemplo n.º 17
0
    public override void Death()
    {
        MyAnimator.ResetTrigger("death");
        MyAnimator.SetTrigger("idle");
        health = 30;

        //If dropsLoot is true he'll drop a MoneyBag
        if (dropsLoot)
        {
            Instantiate(moneyBag, transform.position, transform.rotation);
        }

        //Elf disappears/dies
        MyAnimator.gameObject.SetActive(false);

        //transform.position = startPos;
    }
Ejemplo n.º 18
0
    public override void Death()
    {
        //To respawn the enemy
        MyAnimator.ResetTrigger("die");
        MyAnimator.SetTrigger("idle");


        Player.score += 20;
        GameControl.control.coins += 20;
        //To respawn
        //transform.position = startPos;
        //health = 10;


        //To destroy the enemy
        Destroy(gameObject);
    }
Ejemplo n.º 19
0
    public override void Death()
    {
        fellOff  = false;
        rained   = false;
        time     = 0;
        this.tag = "Enemy";
        MyAnimator.SetTrigger("idle");
        MyAnimator.ResetTrigger("die");
        healthStat.MaxVal     = GameManager.Instance.EnemyHealth;
        healthStat.CurrentVal = healthStat.MaxVal;
        monsterLevel          = GameManager.Instance.EnemyLevel;
        //for when not death
        //healthStat.CurrentVal += 10;
        healthCanvas.enabled = false;
        Target = null;

        transform.position = new Vector3(startPos.x + UnityEngine.Random.Range(2.5f, 6.5f), startPos.y, startPos.z);
    }
Ejemplo n.º 20
0
    public void ToGrab()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (!grabbed)
            {
                Physics2D.queriesStartInColliders = false;
                hit = Physics2D.Raycast(transform.position, Vector2.right * transform.localScale.x, distance);

                if (hit.collider != null && hit.collider.tag == "Pick Up")
                {
                    grabbed = true;

                    hit.transform.SetParent(this.transform, true);

                    MyAnimator.SetTrigger("pickup");
                    MyAnimator.SetBool("carry", true);
                    MyAnimator.ResetTrigger("throw");
                }
            }
            else if (Physics2D.OverlapPoint(holdpoint.position, notgrabbed))
            {
                grabbed = false;

                if (hit.collider.gameObject.GetComponent <Rigidbody2D>() != null)
                {
                    hit.rigidbody.isKinematic = false;
                    hit.collider.isTrigger    = false;

                    hit.transform.parent = null;

                    hit.collider.gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(transform.localScale.x, 1) * throwforce;
                    MyAnimator.SetTrigger("throw");
                    MyAnimator.SetBool("carry", false);
                }
            }

            if (grabbed)
            {
                hit.collider.gameObject.transform.position = holdpoint.position;
            }
        }
    }
Ejemplo n.º 21
0
    private bool Isgrounded()
    {
        if (myRigidbody.velocity.y <= 0)
        {
            foreach (Transform point in GroundPoints)
            {
                Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, GroundRadius, WhatIsGround);

                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].gameObject != gameObject)
                    {
                        MyAnimator.ResetTrigger("Jump");
                        MyAnimator.SetBool("Land", false);
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 22
0
    private Vector2 Dashing(Vector2 v)
    {
        // End of dash
        if (dashCurrentTime >= dashDuration)
        {
            // Reset the dash settings
            dashCurrentTime = 0;
            isDashing       = false;
            canDash         = false;
            StartCoroutine(ResetDash());
            // Stop velocity
            v = Vector2.zero;

            MyAnimator.ResetTrigger("Dash");
        }
        else
        {
            // Continue the dash
            dashCurrentTime += Time.deltaTime;
            v.x              = dashForce * direction.x;
            v.y              = dashForce * direction.y;
        }
        return(v);
    }
Ejemplo n.º 23
0
 private void ResetTrig(string name)
 {
     MyAnimator.ResetTrigger(name);
     actState = ActState.StandBy;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Handles the blocking animations for the AI
 /// </summary>
 private void BlockHandler()
 {
     //if the boss is not blocking yet and if his health is between the right range of health % then start blocking
     //if (!isBlocking && !isBlockingSecond && !isBlockingThird)
     //{
     //    if (((CurrentBossHealth / MaxBossHealth) <= .7f) && ((CurrentBossHealth / MaxBossHealth) > .4f))
     //    {
     //        MyAnimator.ResetTrigger("BlockDamaged");
     //        MyAnimator.SetTrigger("Block");
     //        isBlocking = true;
     //    }
     //}
     //if the boss is not blocking yet and if his health is between the right range of health % then start blocking
     //if (isBlocking && !isBlockingSecond && !isBlockingThird)
     //{
     //    if (((CurrentBossHealth / MaxBossHealth) <= .4f) && ((CurrentBossHealth / MaxBossHealth) > .1f))
     //    {
     //        MyAnimator.ResetTrigger("BlockDamaged");
     //        MyAnimator.SetTrigger("Block");
     //        isBlockingSecond = true;
     //    }
     //}
     //if the boss is not blocking yet and if his health is between the right range of health % then start blocking
     //if (isBlocking && isBlockingSecond && !isBlockingThird)
     //{
     //    if (((CurrentBossHealth / MaxBossHealth) <= .1f) && ((CurrentBossHealth / MaxBossHealth) > 0))
     //    {
     //        MyAnimator.ResetTrigger("BlockDamaged");
     //        MyAnimator.SetTrigger("Block");
     //        isBlockingThird = true;
     //    }
     //}
     // if the boss takes damage then trigger the animation
     if (TakesDamage)
     {
         if (isBlocking && !isBlockingSecond && !isBlockingThird)
         {
             MyAnimator.SetTrigger("BlockDamaged");
         }
         if (isBlocking && isBlockingSecond && !isBlockingThird)
         {
             MyAnimator.SetTrigger("BlockDamaged");
         }
         if (isBlocking && isBlockingSecond && isBlockingThird)
         {
             MyAnimator.SetTrigger("BlockDamaged");
         }
     }
     // if the boss takes a heavy hit then break his block and trigger animation
     if (IsHeavyHit)
     {
         if (isBlocking && !isBlockingSecond && !isBlockingThird)
         {
             MyAnimator.SetTrigger("BlockBreak");
             MyAnimator.ResetTrigger("BlockDamaged");
             MyAnimator.ResetTrigger("Block");
         }
         if (isBlocking && isBlockingSecond && !isBlockingThird)
         {
             MyAnimator.SetTrigger("BlockBreak");
             MyAnimator.ResetTrigger("BlockDamaged");
             MyAnimator.ResetTrigger("Block");
         }
         if (isBlocking && isBlockingSecond && isBlockingThird)
         {
             MyAnimator.SetTrigger("BlockBreak");
             MyAnimator.ResetTrigger("BlockDamaged");
             MyAnimator.ResetTrigger("Block");
         }
     }
 }