Example #1
0
    private void Update()
    {
        //Sets Layers to INT for Raycasting
        LayerMask = RayLayers.value;
        RaycastHit hit;

        //Debug Ray
        Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * RayLength, Color.yellow);

        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, RayLength, LayerMask))
        {
            Debug.Log("HIT! " + hit.collider.name);
            //Enable Text
            LabelText.text = "Press 'E' to pick up " + hit.collider.name;
            LabelText.gameObject.SetActive(true);

            if (Input.GetKeyDown(KeyCode.E))
            {
                Debug.Log("E hit");
                RayObject = hit.collider.transform;

                //Set parent and copy Transform to set pos and rot
                RayObject.parent   = HandLocation;
                RayObject.position = HandLocation.position;
                RayObject.rotation = HandLocation.rotation;

                RayObject.GetComponent <WeaponInfo>().Pickup();

                wp.LoadWeaponStats(RayObject.gameObject.GetComponent <WeaponInfo>());
            }
        }
        else
        {
            HideLabel();
        }
    }