示例#1
0
    public void DealDamage(float damage)
    {
        AudiomanagerScript.PlaySound("playerhit");

        health -= damage;
        if (health > 100)
        {
            if (gameObject.layer == 9)
            {
                health = 100;
            }
            else if (gameObject.layer == 10)
            {
                health = 100;
            }
        }

        currentHealth = health;
        //pasekHP.SetHealth(health);
        if (health <= 0)
        {
            Debug.Log("Health loss");
            if (gameObject.layer == 9)
            {
                AudiomanagerScript.PlaySound("deatchSound");

                Debug.Log("Health loss1");
                koniec.SetActive(true);
                //pasekHP.SetHealth(health);
                // healthbarUI.SetHealth(health);
            }
            else if (gameObject.layer == 10)
            {
                Debug.Log("Health loss2");
                koniec.SetActive(true);
                //healthbarUI.SetHealth(health);
            }
            else if (gameObject.tag == "Boss")
            {
                Destroy(gameObject);
                koniecGry.SetActive(true);
            }
            else
            {
                if (drops)
                {
                    GameObject droppped = Instantiate(theDrops, dropPoint.position, dropPoint.rotation);
                    droppped.SetActive(true);
                }
                Destroy(gameObject);
                Debug.Log("Health loss");
            }
        }
    }
示例#2
0
    void Update()
    {
        if (Input.GetKey(KeyCode.LeftArrow))
        {
            if (movespeed > -0.03f)
            {
                movespeed -= 0.001f;
            }
            blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
            direction = -1;
            animator.SetFloat("isSpeed", movespeed * -100);
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
            if (movespeed < 0.03f)
            {
                movespeed += 0.001f;
            }
            blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
            direction = 1;
            animator.SetFloat("isSpeed", movespeed * 100);
        }
        if (!Input.GetKey(KeyCode.RightArrow) && !Input.GetKey(KeyCode.LeftArrow))
        {
            animator.SetFloat("isSpeed", 0);
        }
        if (Input.GetKey(KeyCode.DownArrow))
        {
            animator.SetBool("isSliding", true);
            this.GetComponent <Rigidbody2D>().AddForce(blackPlayer.transform.up * -1);
            if (Input.GetKey(KeyCode.DownArrow) && jestNaPlatformie == true)
            {
                if (waitTime <= 0)
                {
                    boxCollider2D.isTrigger = true;
                    waitTime = 0.5f;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }

            //blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
        }
        else
        {
            animator.SetBool("isSliding", false);
        }

        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            waitTime = 0.5f;
        }
        if (Input.GetKey(KeyCode.UpArrow) && Grounded())
        {
            animator.SetBool("Jump", true);
            if (betterjump)
            {
                this.GetComponent <Rigidbody2D>().velocity        = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, 0f);
                this.GetComponent <Rigidbody2D>().angularVelocity = 0f;
                this.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 12, ForceMode2D.Impulse);
            }
            else
            {
                this.GetComponent <Rigidbody2D>().velocity        = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, 0f);
                this.GetComponent <Rigidbody2D>().angularVelocity = 0f;
                this.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 9, ForceMode2D.Impulse);
                blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
            }
        }
        else if (Grounded() == true)
        {
            animator.SetBool("Jump", false);
        }
        if (Input.GetMouseButtonDown(1))
        {
            if (shotReady && magazine == 2 && weapon == 0)
            {
                Vector3 blackPos = Camera.WorldToScreenPoint(blackPlayer.transform.position);
                Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, blackPlayer.transform.position.z);
                Vector2 diff     = new Vector2(blackPos.x - mousePos.x, blackPos.y - mousePos.y);
                diff      = diff / Mathf.Sqrt(diff.x * diff.x + diff.y * diff.y);
                shotReady = false;
                this.GetComponent <Rigidbody2D>().AddForce(blackPlayer.transform.up * diff.y * 250);
                movespeed    += diff.x * 0.05f;
                shotCountdown = 300;

                float angle = AngleBetweenTwoPoints(mousePos, blackPos);
                Blast.SetActive(true);

                Blast.transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, angle));
                magazine = 0;
            }
            blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
        }
        if (cannonShotReady && magazine == 0)
        {
        }
        if (Input.GetMouseButtonDown(0))
        {
            if (shotReady && magazine > 0 && weapon == 0)
            {
                AudiomanagerScript.PlaySound("fire");
                Vector3 blackPos = Camera.WorldToScreenPoint(blackPlayer.transform.position);
                Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, blackPlayer.transform.position.z);
                Vector2 diff     = new Vector2(blackPos.x - mousePos.x, blackPos.y - mousePos.y);
                diff      = diff / Mathf.Sqrt(diff.x * diff.x + diff.y * diff.y);
                shotReady = false;
                this.GetComponent <Rigidbody2D>().AddForce(blackPlayer.transform.up * diff.y * 100);
                movespeed     += diff.x * 0.01f;
                Bcontrol.xDiff = -diff.x;
                Bcontrol.yDiff = -diff.y;
                GameObject BulletClone = Instantiate(Bullet, blackPlayer.transform.position, Quaternion.identity);
                BulletClone.SetActive(true);

                magazine--;
                singleShotCountdown = 50;
                shotCountdown       = 200;
            }
            else if (cannonShotReady && weapon == 1)
            {
                if (bettercannon)
                {
                    Vector3 blackPos = Camera.WorldToScreenPoint(blackPlayer.transform.position);
                    Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, blackPlayer.transform.position.z);
                    Vector2 diff     = new Vector2(blackPos.x - mousePos.x, blackPos.y - mousePos.y);
                    diff            = diff / Mathf.Sqrt(diff.x * diff.x + diff.y * diff.y);
                    cannonShotReady = false;
                    this.GetComponent <Rigidbody2D>().AddForce(blackPlayer.transform.up * diff.y * 200);
                    movespeed     += diff.x * 0.015f;
                    Ccontrol.xDiff = -diff.x;
                    Ccontrol.yDiff = -diff.y;
                    GameObject CannonClone = Instantiate(Cannon, blackPlayer.transform.position, Quaternion.identity);
                    CannonClone.SetActive(true);

                    cannonCD    = 25;
                    cannonTimer = 0;
                }
                else
                {
                    Vector3 blackPos = Camera.WorldToScreenPoint(blackPlayer.transform.position);
                    Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, blackPlayer.transform.position.z);
                    Vector2 diff     = new Vector2(blackPos.x - mousePos.x, blackPos.y - mousePos.y);
                    diff            = diff / Mathf.Sqrt(diff.x * diff.x + diff.y * diff.y);
                    cannonShotReady = false;
                    this.GetComponent <Rigidbody2D>().AddForce(blackPlayer.transform.up * diff.y * 200);
                    movespeed     += diff.x * 0.015f;
                    Ccontrol.xDiff = -diff.x;
                    Ccontrol.yDiff = -diff.y;
                    GameObject CannonClone = Instantiate(Cannon, blackPlayer.transform.position, Quaternion.identity);
                    CannonClone.SetActive(true);

                    cannonCD    = 500;
                    cannonTimer = 0;
                }
            }

            blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
        }

        if (Input.GetMouseButtonDown(2))
        {
            weapon++;
            if (weapon > 1)
            {
                weapon = 0;
            }
            blackPlayer.transform.position = new Vector3((blackPlayer.transform.position.x + movespeed), blackPlayer.transform.position.y, blackPlayer.transform.position.z);
        }



        if (movespeed > 0)
        {
            movespeed -= 0.0001f;
        }
        else if (movespeed < 0)
        {
            movespeed += 0.0001f;
        }

        if (movespeed < 0.0001f && movespeed > -0.0001f)
        {
            movespeed = 0;
        }

        if (magazine < 2)
        {
            shotTimer++;
            if (shotTimer == 20)
            {
                Blast.SetActive(false);
            }
            if (shotTimer == singleShotCountdown && magazine > 0)
            {
                shotReady = true;
            }
            if (shotTimer > shotCountdown)
            {
                AudiomanagerScript.PlaySound("reloadSound");
                shotReady = true;
                shotTimer = 0;
                magazine  = 2;
            }
        }

        if (cannonShotReady == false)
        {
            cannonTimer++;
            if (cannonTimer == cannonCD)
            {
                cannonShotReady = true;
            }
        }
        Blast.transform.position         = blackPlayer.transform.position;
        blackPlayer.transform.localScale = new Vector3(Mathf.Abs(blackPlayer.transform.localScale.x) * direction, blackPlayer.transform.localScale.y, blackPlayer.transform.localScale.z);

        Vector3 blackPosition = Camera.WorldToScreenPoint(blackPlayer.transform.position);

        Vector3 mousePosition = new Vector3(Input.mousePosition.x, Input.mousePosition.y, blackPlayer.transform.position.z);
        Vector3 aimdirection  = (mousePosition - transform.position).normalized;
        //float anglex = Mathf.Atan2(aimdirection.y, aimdirection.x) * Mathf.Rad2Deg;
        float anglex = AngleBetweenTwoPoints(mousePosition, blackPosition);

        aimTransform.eulerAngles = new Vector3(0, 0, anglex);
        Vector3 loaclSkale = Vector3.one;

        if (direction == -1)
        {
            loaclSkale.x = -1;
        }
        else
        {
            loaclSkale.x = 1;
        }

        if (anglex > 90 || anglex < -90)
        {
            loaclSkale.y = -1f;
        }
        else
        {
            loaclSkale.y = +1f;
        }
        aimTransform.localScale = loaclSkale;
    }
示例#3
0
    void Update()
    {
        if (Input.GetKey("a"))
        {
            if (movespeed > -0.03f)
            {
                movespeed -= 0.001f;
            }
            direction = -1;


            animator.SetFloat("isSpeed", movespeed * -100);
        }

        if (Input.GetKey("d"))
        {
            if (movespeed < 0.03f)
            {
                movespeed += 0.001f;
            }
            direction = 1;
            animator.SetFloat("isSpeed", movespeed * 100);
        }
        if (!Input.GetKey("d") && !Input.GetKey("a"))
        {
            animator.SetFloat("isSpeed", 0);
        }
        if (Input.GetKey("s"))
        {
            this.GetComponent <Rigidbody2D>().AddForce(whitePlayer.transform.up * -1);
            animator.SetBool("isSliding", true);

            if (Input.GetKey("s") && jestNaPlatformie == true)
            {
                if (waitTime <= 0)
                {
                    boxCollider2D.isTrigger = true;
                    waitTime = 0.5f;
                }
                else
                {
                    waitTime -= Time.deltaTime;
                }
            }
        }
        else
        {
            animator.SetBool("isSliding", false);
        }



        if (Input.GetKey("w") && Grounded() == true)
        {
            animator.SetBool("Jump", true);
            if (betterjump)
            {
                this.GetComponent <Rigidbody2D>().velocity        = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, 0f);
                this.GetComponent <Rigidbody2D>().angularVelocity = 0f;
                this.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 6, ForceMode2D.Impulse);
            }
            else
            {
                this.GetComponent <Rigidbody2D>().velocity        = new Vector2(this.GetComponent <Rigidbody2D>().velocity.x, 0f);
                this.GetComponent <Rigidbody2D>().angularVelocity = 0f;
                this.GetComponent <Rigidbody2D>().AddForce(Vector2.up * 5, ForceMode2D.Impulse);
            }
        }
        else if (Grounded() == true)
        {
            animator.SetBool("Jump", false);
        }
        if (Input.GetKey(KeyCode.LeftShift) && canDash)
        {
            if (Grounded() == false)
            {
                animator.SetBool("Jump", false);
            }



            animator.SetBool("isDash", true);

            canDash       = false;
            movespeed    += direction * 0.1f;
            dashCDTimer   = 0;
            dashTimer     = 0;
            dashDirection = direction;
            hittable      = false;
        }
        if (!Input.GetKey(KeyCode.LeftShift))
        {
            animator.SetBool("isDash", false);
        }
        if (Input.GetKey(KeyCode.Space) && canSlash)
        {
            AudiomanagerScript.PlaySound("meeleSound");
            if (Grounded() == false)
            {
                animator.SetBool("Jump", false);
            }



            animator.SetTrigger("isAttacking");

            if (betterslash)
            {
                if (Input.GetKey("s"))
                {
                    slashCD     = 180;
                    slashOffset = new Vector3(0, -1, 0);
                    this.GetComponent <Rigidbody2D>().AddForce(whitePlayer.transform.up * -50);
                }
                else if (Input.GetKey("w"))
                {
                    slashCD     = 350;
                    slashOffset = new Vector3(0, 2, 0);
                    this.GetComponent <Rigidbody2D>().AddForce(whitePlayer.transform.up * 50);
                }
                else
                {
                    slashCD     = 120;
                    slashOffset = new Vector3(0, 0, 0);
                }
                canSlash = false;
                slash.SetActive(true);
                slash.transform.localScale = new Vector3(Mathf.Abs(slash.transform.localScale.x) * direction, slash.transform.localScale.y, slash.transform.localScale.z);
            }
            else
            {
                if (Input.GetKey("s"))
                {
                    slashCD     = 180;
                    slashOffset = new Vector3(0, -1, 0);
                    this.GetComponent <Rigidbody2D>().AddForce(whitePlayer.transform.up * -50);
                }
                else if (Input.GetKey("w"))
                {
                    slashCD     = 350;
                    slashOffset = new Vector3(0, 2, 0);
                    this.GetComponent <Rigidbody2D>().AddForce(whitePlayer.transform.up * 50);
                }
                else
                {
                    slashCD     = 120;
                    slashOffset = new Vector3(0, 0, 0);
                }
                canSlash = false;
                slash.SetActive(true);
                slash.transform.localScale = new Vector3(Mathf.Abs(slash.transform.localScale.x) * direction, slash.transform.localScale.y, slash.transform.localScale.z);
            }
        }
        //float scale;

        whitePlayer.transform.position = new Vector3((whitePlayer.transform.position.x + movespeed), whitePlayer.transform.position.y, whitePlayer.transform.position.z);
        //float playerXdiff = (whitePlayer.transform.position.x + blackPlayer.transform.position.x) / 2;
        //float playerYdiff = (whitePlayer.transform.position.y + blackPlayer.transform.position.y) / 2;
        //Camera.transform.position = new Vector3(playerXdiff,playerYdiff , Camera.transform.position.z);
        //if (Mathf.Abs(whitePlayer.transform.position.x - blackPlayer.transform.position.x) > 10 && Mathf.Abs(whitePlayer.transform.position.x - blackPlayer.transform.position.x) < 20)
        //{
        //    scale =Mathf.Abs(  (whitePlayer.transform.position.x - blackPlayer.transform.position.x)/10f);
        //}
        //else if (Mathf.Abs(whitePlayer.transform.position.x - blackPlayer.transform.position.x) < 10 )
        //{
        //    scale = 1f;
        //}
        //else
        //{
        //    scale = 2f;
        //}
        //float scaleY = 1;
        //if (Mathf.Abs(whitePlayer.transform.position.y - blackPlayer.transform.position.y) > 5 && Mathf.Abs(whitePlayer.transform.position.y - blackPlayer.transform.position.y) < 10)
        //{
        //    scaleY = Mathf.Abs((whitePlayer.transform.position.y - blackPlayer.transform.position.y) / 5f);
        //}
        //else if (Mathf.Abs(whitePlayer.transform.position.y - blackPlayer.transform.position.y) < 5)
        //{
        //    scaleY = 1f;
        //}
        //else
        //{
        //    scaleY = 2f;
        //}
        //scale = (scale + scaleY) / 2f;
        //CCamera.orthographicSize = standardCamera*scale;


        if (movespeed > 0)
        {
            movespeed -= 0.0001f;
        }
        else if (movespeed < 0)
        {
            movespeed += 0.0001f;
        }

        if (movespeed < 0.0001f && movespeed > -0.0001f)
        {
            movespeed = 0;
        }

        if (canDash == false)
        {
            if (dashTimer < dashTime)
            {
                dashTimer++;
            }
            else if (dashTimer == dashTime)
            {
                dashTimer++;
                movespeed -= dashDirection * 0.08f;
            }
            else
            {
                hittable = true;
            }


            if (dashCDTimer < dashCD)
            {
                dashCDTimer++;
            }
            else
            {
                canDash = true;
            }
        }



        if (canSlash == false)
        {
            slash.transform.position = whitePlayer.transform.position + slashOffset;
            if (slashTimer < slashCD)
            {
                slashTimer++;
            }
            else
            {
                canSlash   = true;
                slashTimer = 0;
            }
            if (slashTimer == 80)
            {
                slash.SetActive(false);
            }
        }

        whitePlayer.transform.localScale = new Vector3(Mathf.Abs(whitePlayer.transform.localScale.x) * direction, whitePlayer.transform.localScale.y, whitePlayer.transform.localScale.z);
    }