Пример #1
0
    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float y = Input.GetAxis("Vertical");

        rb.velocity = new Vector2(x, y) * speed;

        //will need to change for controller
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (holdingSomething)
            {
                //put down what you're holding
                holdingSomething = false;
                BoxCollider2D box = whatHolding.gameObject.GetComponent <BoxCollider2D>();
                if (box != null)
                {
                    box.enabled = false;
                }
                whatHolding.SetParent(manager.GetRoomTransform());
                whatHolding = null;
            }
            else
            {
                //raycast backwards
                RaycastHit2D hit = Physics2D.Raycast(cursorTip.transform.position, Vector2.zero, Mathf.Infinity, layermask);
                if (hit.collider != null)
                {
                    //make the hit a child of the cursor
                    holdingSomething = true;
                    whatHolding      = hit.transform;
                    BoxCollider2D box = whatHolding.gameObject.GetComponent <BoxCollider2D>();
                    if (box != null)
                    {
                        box.enabled = false;
                    }
                    whatHolding.SetParent(transform);
                }
            }
        }
    }