RayCast relative to camera stays in 1 place.

When I start my game the raycast moves with the mouse movement but it stays in the same place where it begins.

using UnityEngine;
using System.Collections;

namespace CameraRayCastLine {

	public class PickUpRayCast : MonoBehaviour {
		// The camera gameobject.
			public GameObject Camera;
	
	// The camera position and direction.
		// The relative camera position with axis. 
			float CameraPositionX;
			float CameraPositionY;
			float CameraPositionZ;
		// The relative camera direction.
			Vector3 CameraDirection;
		// The camera position in Vector3 form.
			Vector3 CameraPositionVector;
			
	// The RayCast information.
		// The length of the RayCast. 
			public float RayCastLength = 10;
		// The color of the RayCast in the debug.
			public Color CameraRayCastColor = Color.yellow;
		// The bool for the RayCast.
			public bool CameraRayCast;

		void Start () {
			// The code that finds the camera.
				Camera = GameObject.Find("MainCamera");
			// The code that gets the raw camera position axis and converts them to floats.
				CameraPositionX = Camera.transform.position.x;
				CameraPositionY = Camera.transform.position.y;
				CameraPositionZ = Camera.transform.position.z;
			// The code that changes the floats into a refined Vector3.
				CameraPositionVector = new Vector3 (CameraPositionX, CameraPositionY, CameraPositionZ);
			// The refining of the RayCast.
				CameraRayCast = Physics.Raycast(CameraPositionVector, CameraDirection, RayCastLength);
		
		}
	
		void Update () {
			// The camera direction refined into Vector3 form.
				Vector3 CameraDirection = Camera.transform.TransformDirection(Vector3.forward);
			// The actual RayCast.
				CameraRayCast = true;
			// The debug line that makes the raycast visible in the scene view.
				Debug.DrawRay(CameraPositionVector, CameraDirection, CameraRayCastColor, RayCastLength);
		}
	}
}

@RobertVanDerLeeuw

Your problem is that you do not update your CameraPositionVector.

In the Start method you do :

// The code that changes the floats into a refined Vector3.
CameraPositionVector = new Vector3 (CameraPositionX, CameraPositionY, CameraPositionZ);

and you do not update this position in the Update method (so it doesn’t change, and keep the initial value).

More, I don’t really understand why you declare

// The relative camera position with axis. 
float CameraPositionX;
float CameraPositionY;
float CameraPositionZ;
// The relative camera direction.
Vector3 CameraDirection;
// The camera position in Vector3 form.
Vector3 CameraPositionVector;

since all the information is contained in the camera itself. I think you could delete these member variables and simply make :

Debug.DrawRay(Camera.transform.position, Camera.transform.forward, CameraRayCastColor, RayCastLength);

im in a hurry, but shortly put, your ray will go forwards in the z axis, from where the camera is at, now i asume you want to have it aim towards the mouse, in which case i would recommend you make a ray variable like so: Ray ray = Camera.main.ScreenToRayPoint(Input.mousePosition); (that’s how it goes if memory serves right).

then the ray wil always go from the camera, to your mouse and then you can put in length and all that after.

sorry if this isn’t the answer you were looking for but again, in a hurry, best of luck.