Example #1
0
    void FixedUpdate()
    {
        if (menuCanvas.gameObject.activeSelf == true)
        {
            return;
        }
        if (climbing)
        {
            transform.position = transform.position + Vector3.up * verticalMove * Time.fixedDeltaTime;
            // rb.MovePosition(rb.position + Vector2.up * verticalMove * Time.fixedDeltaTime);
        }

        if (verticalMove < 0)
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up);

            // If it hits something...
            if (hit.collider != null)
            {
                Debug.Log(hit.collider.transform.gameObject.tag);
                if (hit.collider.transform.gameObject.tag == "PassThrough")
                {
                    Debug.Log("hey");
                    transform.position = new Vector3(transform.position.x, transform.position.y - 1.5f, transform.position.z);
                }
            }
        }

        ctrl.Move(horizontalMove * Time.fixedDeltaTime, false, jump);
        jump = false;

        Transform texture = pickableTexture();

        if (texture != null && liftThrowPressed && holdedTexture == null)
        {
            Debug.Log("Picked");
            holdedTexture = texture;
        }
        else if (liftThrowPressed && holdedTexture != null)
        {
            Debug.Log("Thrown");
            Vector2 throwForce = new Vector2(ctrl.intFaceDir(), 1) * throwStrenght;
            holdedTexture.GetComponent <Rigidbody2D>().AddForce(throwForce, ForceMode2D.Impulse);//(ctrl.intFaceDir() + transform.up) * throwStrenght);
            holdedTexture = null;
        }



        liftThrowPressed = false;


        if (interactPrompt.gameObject.activeSelf && Mathf.Sign(interactPrompt.lossyScale.x) < 0)
        {
            interactPrompt.localScale = new Vector3(interactPrompt.localScale.x * -1, interactPrompt.localScale.y, interactPrompt.localScale.z);
        }

        if (interacting && currentInteractible)
        {
            if (currentInteractible.name == "TV" && wiresCollected > 0)
            {
                wiresCollected--;
                wiresUsed++;
                inventory.setWires(wiresCollected);
                if (wiresUsed == 3)
                {
                    SetGrayscale(false);
                }
            }
            else if (currentInteractible.name == "SoundFix" && brokenSoundsCollected > 0)
            {
                brokenSoundsCollected--;
                fixedSoundsCollected++;
                inventory.setBrokenSounds(brokenSoundsCollected);
                inventory.setFixedSounds(fixedSoundsCollected);
            }
            else if (currentInteractible.name == "Ipod" && fixedSoundsCollected > 0)
            {
                fixedSoundsCollected--;
                fixedSoundsUsed++;
                inventory.setFixedSounds(fixedSoundsCollected);
            }
            else if (currentInteractible.name == "EmptyDoor")
            {
                Debug.Log("Something is missing here");
            }
            else if (currentInteractible.name == "Door")
            {
                Debug.Log("YOU WIN");
                Application.Quit();
            }
        }

        interacting = false;
    }