Пример #1
0
    void FixedUpdate()
    {
        Rogue = GameObject.Find("Rogue");
        rogueScript = Rogue.GetComponent<RayoScriptLevel3>();
        if (rogueScript.dead)
        {
            anim.SetBool("walk", false);
            anim.SetBool("attack", false);
        }
        float playerposition = target.position.x;
        range = Vector2.Distance(transform.position, target.position);
        if ((((range > maxDistance) || (target.position.y - transform.position.y > 0 && !reversePath) || (transform.position.y - target.position.y > 0 && reversePath)) && !spotted))
        {
            anim.SetBool("walk", true);
            anim.SetBool("attack", false);
            if (transform.position.y == endpositionY)
            {
                Flip();
                if (!reversePath)
                {
                    endpositionX = -13;
                    endpositionY = -79;
                    reversePath = true;
                }
                else
                {
                    endpositionX = -13;
                    endpositionY = -55;
                    reversePath = false;
                }
            }
            transform.position = Vector2.MoveTowards(transform.position, new Vector2(endpositionX, endpositionY), speed * Time.deltaTime);
        }

        //To find and move to the Player
        else if (!rogueScript.dead)
        {
            spotted = true;
            maxDistance = 50;
            doDamage = false;
            playerHit = false;
            if (playerposition > transform.position.x && !facingRight)
            {
                Flip();
            }
            else if (transform.position.x > playerposition && facingRight)
            {
                Flip();
            }


            //If Player is in range, start moving towards.

            if (range < maxDistance)
            {
                anim.SetBool("walk", true);
                transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
            }
            else {
                anim.SetBool("walk", false);
            }
            if (range > attackDistance)
            {
                anim.SetBool("attack", false);
            }



            if (range < 3f)
            {
                if (anim.GetBool("attack") == true)
                {
                    playerHit = true;
                    doDamage = true;
                }
            }
        }
        //Death
        if (knightLife <= 0)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, 2); //move on the z.
            anim.SetBool("dead", true);
            anim.SetBool("attack", false);
            anim.SetBool("walk", false);
            speed = 0f;
            knightDead = true;
            rb.isKinematic = true;
            BoxCollider2D b; //Remove the collision box.
            b = GetComponent<BoxCollider2D>();
            b.enabled = false;
            if (count == 1)
            {
                rogueScript.rayoScore += 50;
                count++;
            }
        }
    }
Пример #2
0
    void FixedUpdate()
    {
        Rogue = GameObject.Find("Rogue");
        rogueScript = Rogue.GetComponent<RayoScriptLevel3>();
        if (rogueScript.dead)
        {
            anim.SetBool("walk", false);
            anim.SetBool("attack", false);
        }
        float playerposition = target.position.x;
        range = Vector2.Distance(transform.position, target.position);


        //To find and move to the Player
        if (!rogueScript.dead && PlayerPrefs.GetInt("bossAttack") == 1)
        {
            maxDistance = 50;
            doDamage = false;
            playerHit = false;
            if (playerposition > transform.position.x && !facingRight)
            {
                Flip();
            }
            else if (transform.position.x > playerposition && facingRight)
            {
                Flip();
            }


            //If Player is in range, start moving towards.

            if (range < maxDistance)
            {
                anim.SetBool("walk", true);
                transform.position = Vector2.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
            }
            else {
                anim.SetBool("walk", false);
            }
            if (range > attackDistance)
            {
                anim.SetBool("attack", false);
            }



            if (range < 5f && PlayerPrefs.GetInt("bossAttack") == 1)
            {
                if (anim.GetBool("attack") == true)
                {
                    playerHit = true;
                    doDamage = true;
                }
            }
        }
        //Death
        if (knightLife <= 0)
        {
            transform.position = new Vector3(transform.position.x, transform.position.y, 2); //move on the z.
            anim.SetBool("dead", true);
            anim.SetBool("attack", false);
            anim.SetBool("walk", false);
            speed = 0f;
            knightDead = true;
            rb.isKinematic = true;
            BoxCollider2D b; //Remove the collision box.
            b = GetComponent<BoxCollider2D>();
            b.enabled = false;
            PlayerPrefs.SetInt("bossAttack", 2);
            if (count == 1)
            {
                rogueScript.rayoScore += 300;
                count++;
            }
        }
    }