Exemplo n.º 1
0
        private void Update()
        {
            Transform camTransform = _camera.transform;
            Ray       ray          = new Ray(camTransform.position, camTransform.forward);

            if (Physics.Raycast(ray, out var hit, pickupRange, pickupMask))
            {
                ItemPickup pickup = hit.transform.GetComponent <ItemPickup>();
                // Pointing at new target object not the same as previous target
                if (_raycastObj != pickup)
                {
                    // Reset previous target material
                    if (_raycastObj != null)
                    {
                        _raycastObj.Highlight(false);
                    }

                    // Store target and change material to highlight material
                    _raycastObj = pickup;
                    _raycastObj.Highlight(true);
                    OnLookAt?.Invoke(_raycastObj.ItemName);
                }
                // Pickup button has been pressed
                if (Input.GetButtonDown("Pickup"))
                {
                    if (pickup != null)
                    {
                        PickupItem(pickup);
                        ResetTarget();
                    }
                }
            }
 /// <summary>
 /// Called once the players headset looks at a taget
 /// </summary>
 public static void LookAt(RaycastHit hit)
 {
     OnLookAt?.Invoke(hit);
 }