// <summary> // Cast a ray from the middle of the player's screen and detects whether // the player is looking at a cart or not. // </summary> private void HandleRaycasting() { playerLookRay = mainCamera.ViewportPointToRay(screenCenter); layerMask = LayerMask.GetMask(cartLayerName); isLookingAtCart = Physics.Raycast(playerLookRay, out hitCart, maxDistanceGrab, layerMask); Debug.DrawLine(playerLookRay.origin, hitCart.point); if (isLookingAtCart) { cartLastLookedAt = hitCart.transform; cartLastLookedAtCart = cartLastLookedAt.GetComponent <Cart>(); // Activate the outline if the player is looking at cart // it can grab. if (!isHoldingCart) { cartLastLookedAtCart.ActivateOutline(); } // If we're not looking at a cart but we have looked at cart before, // deactivate it's outline. } else if (cartLastLookedAt != null) { cartLastLookedAtCart.DeactivateOutline(); } }