Raycast Help to pick up food

Hello,

i’m trying to get a Raycast to help locate food in my FPS and then when i hit a key, it add it’s value to the associated slider.

Here is the script i’ve put on my player to interact with the food:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Interraction : MonoBehaviour
{

    public float interactRange = 3f;
    public Camera FPSCamera;
    public Slider sliderFaim;

    private Nourriture nourriture;
    public bool debugRay = false;

    private void Update()
    {
        Ray ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
        RaycastHit hitInfo;

        if (debugRay == true)
        {
            Debug.DrawRay(ray.origin, ray.direction * interactRange, Color.yellow);
        }

        if (Input.GetKeyDown(KeyCode.E))
        {

            if (Physics.Raycast(ray, out hitInfo, interactRange))
            {
                if (hitInfo.collider.tag == "Nourriture")
                {
                    nourriture = hitInfo.collider.GetComponent<Nourriture>();

                    if (nourriture.sorteNourriture == Nourriture.SorteNourriture.Faim)
                    {
                        sliderFaim.value = sliderFaim.value += nourriture.montantaajouter; //pretty sure the error is here...
                        nourriture.DestroyObject();
                    }
                }
            }
        }
    }
}

Here is the code i’ve put on the food (tag=Nourriture):

using UnityEngine;
using System.Collections;

public class Nourriture : MonoBehaviour
{

    public SorteNourriture sorteNourriture = new SorteNourriture();
    public enum SorteNourriture { Vie, Faim, Soif, Stamina };
    public float montantaajouter;

    public void DestroyObject()
    {
        DestroyObject(gameObject);
    }
}

I’d like the montantaajouter value to be added to the sliderFaim. I have no Scripting error but nothing happens… No value added and food item (Nourriture) doesn’t disappear from game.

thanks a lot for your help, would be greatly appreciated.

Seb

I’m not sure if this is what you are looking for but did you try : FPSCamera.ScreenToWorldPoint?

I recommend writing code in english. It will severely help you when looking for help.