Ejemplo n.º 1
0
    private void Update()
    {
        RaycastHit IconHit = new RaycastHit();

        if (Physics.Raycast(_PlayerCam.ScreenPointToRay(Input.mousePosition).origin,
                            _PlayerCam.ScreenPointToRay(Input.mousePosition).direction, out IconHit, 3,
                            Physics.DefaultRaycastLayers))
        {
            if ((IconHit.rigidbody) && (IconHit.rigidbody.isKinematic == false) || IconHit.collider.tag == "Note")
            {
                InteractableIcon.sprite = InteractIcon;
            }
            if (IconHit.collider.tag == "Note" && Input.GetMouseButtonDown(0))
            {
                _UISystem.AddNewNote(IconHit.collider.GetComponent <NoteSystem>().NoteName, IconHit.collider.GetComponent <NoteSystem>().NoteText);
                _UISystem.NoteTitleText.text = IconHit.collider.GetComponent <NoteSystem>().NoteName;
                _UISystem.NoteReadText.text  = IconHit.collider.GetComponent <NoteSystem>().NoteText;
                _UISystem.OpenNoteRead();
                Destroy(IconHit.collider.gameObject);
                StartCoroutine(UpdateText("Note added to notes"));
            }
        }
        else
        {
            InteractableIcon.sprite = DefaultIcon;
        }

        if (!Input.GetMouseButtonDown(0))
        {
            return;
        }

        RaycastHit hit = new RaycastHit();

        if (
            !Physics.Raycast(_PlayerCam.ScreenPointToRay(Input.mousePosition).origin,
                             _PlayerCam.ScreenPointToRay(Input.mousePosition).direction, out hit, 3,
                             Physics.DefaultRaycastLayers))
        {
            return;
        }

        if (!hit.rigidbody || hit.rigidbody.isKinematic)
        {
            return;
        }

        if (!m_SpringJoint)
        {
            var       go   = new GameObject("Rigidbody dragger");
            Rigidbody body = go.AddComponent <Rigidbody>();
            m_SpringJoint    = go.AddComponent <SpringJoint>();
            body.isKinematic = true;
        }

        m_SpringJoint.transform.position = hit.point;
        m_SpringJoint.anchor             = Vector3.zero;

        m_SpringJoint.spring        = k_Spring;
        m_SpringJoint.damper        = k_Damper;
        m_SpringJoint.maxDistance   = k_Distance;
        m_SpringJoint.connectedBody = hit.rigidbody;

        StartCoroutine("DragObject", hit.distance);
    }