Пример #1
0
    // Update is called once per frame
    void Update()
    {
        //Move Left / Right
        if (Input.GetKey(KeyCode.A) || Input.GetKeyDown(KeyCode.Q))
        {
            rb.MovePosition(transform.position + Vector3.right * -speed * Time.deltaTime);
            playerRenderer.transform.rotation = Quaternion.Euler(new Vector3(0, leftAngle, 0));
            lightBag.transform.localScale     = new Vector3(-0.01f, 0.01f, 0.01f);
            mediumBag.transform.localScale    = new Vector3(-0.01f, 0.01f, 0.01f);
            heavyBag.transform.localScale     = new Vector3(-0.01f, 0.01f, 0.01f);
            if (!isJumping)
            {
                animator.Play("Run");
            }
        }
        else if (Input.GetKey(KeyCode.D))
        {
            rb.MovePosition(transform.position + Vector3.right * speed * Time.deltaTime);
            playerRenderer.transform.rotation = Quaternion.Euler(new Vector3(0, rightAngle, 0));
            lightBag.transform.localScale     = new Vector3(0.01f, 0.01f, 0.01f);
            mediumBag.transform.localScale    = new Vector3(0.01f, 0.01f, 0.01f);
            heavyBag.transform.localScale     = new Vector3(0.01f, 0.01f, 0.01f);
            if (!isJumping)
            {
                animator.Play("Run");
            }
        }
        else
        {
            if (!isJumping)
            {
                animator.Play("Idle");
            }
        }

        //Jump
        if (Physics.Raycast(transform.position, Vector3.down, 1.5f))
        {
            isJumping = false;
        }
        else
        {
            isJumping = true;
        }

        if (isJumping)
        {
            animator.Play("Landing");
        }

        if (!isJumping && (Input.GetKeyDown(KeyCode.Z) || Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space)))
        {
            rb.velocity = Vector3.up * jumpSpeed;
            animator.Play("Jump");
            isJumping = true;
        }

        //Pick Close Item
        if (Input.GetMouseButtonDown(0))
        {
            PickableItem pickable = GetClosestItem();
            if (pickable != null)
            {
                weight += pickable.weight;
                closeItems.Remove(pickable);
                bag.Add(pickable);
                Destroy(Instantiate(fxPickUp, pickable.gameObject.transform.position, Quaternion.identity), 2.0f);
                pickable.gameObject.SetActive(false);
                GameObject fxGet = Instantiate(pickable.pickupFX[pickable.randomID], fxGetPoint);
                fxGet.transform.position += new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), 0);
                Destroy(fxGet, 1.0f);
                CheckWeightState();
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            if (bag.Count != 0)
            {
                PickableItem pickable = bag[bag.Count - 1];
                weight -= pickable.weight;
                pickable.gameObject.transform.position = itemDropPoint.position;
                pickable.gameObject.SetActive(true);
                pickable.SetVelocity(Vector3.up * Random.Range(.1f, .2f) + Vector3.right * Random.Range(-.1f, .1f));
                bag.Remove(pickable);
                CheckWeightState();
            }
        }
    }