Problem with Raycast declaration?

Hi guys, can somebody tell me, what is wrong with my code? It seems, the problem is when declaring variables ray and rayCastHit bacause the compiler does not know them afterwards.

using UnityEngine;
using System.Collections;

public class TouchPlayerScript : MonoBehaviour {

	private Ray ray;
	private RaycastHit rayCastHit;
	
	void  Update (){
		if (Input.GetMouseButton (0)) {

			ray = Camera.main.ScreenPointToRay (Input.mousePosition);
			
			if (Physics.Raycast (ray, rayCastHit)) {
				transform.position.x = rayCastHit.point.x;
				transform.position.y = rayCastHit.point.y; 
			}
		}
	}

}

Thanks for any help.

The HitInfo parameter of the raycast method is an “out” parameter, i.e. its used as an output for the method like the return type.

When calling such a method, you need to explicitly acknowledge the out parameter.

if (Physics.Raycast (ray, out rayCastHit))

Thanks. Two of four errors are gone. 2 errors still left and it says:

error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position’. Consider storing the value in a temporary variable