Raycast Script not working

Hello there, I need some help with this raycast script that i converted from JavaScript. I get error everywhere and i dont understand why, is there because i missed some basic stuff or is it because you dont write raycast like this in C#. Let me know THanks! :slight_smile:

RaycastHit rayCasthit;
		Ray raycastRay = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5f, Screen.height*0.5f,0));
		if (Input.GetKeyDown(KeyCode.F))
			if (Physics.Raycast (raycastRay, rayCasthit, 3) && rayCasthit.transform.tag == "WarmSweater" && InventorySystem.WarmSweaterIsPickedUp == false)
				InventorySystem.WarmSweaterIsPickedUp = true;

I believe you are missing an “out” before “rayCastHit” when calling the method.

According to the documentation you need to add out after raycasthit :

 void Update() 
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100)) 
            Debug.DrawLine(ray.origin, hit.point);

So inside this:

if (Physics.Raycast (raycastRay,out
rayCasthit, 3)
==“WarmSweater” && InventorySystem.WarmSweaterIsPickedUp==