I need a raycast to come out from the center of my camera out into the world and stop after a certain limit. I’ve never messed with raycasts before and still trying to learn 3D programming, so this is kind of confusing to me. I currently have some script but it’s not working very well for me, but here is my current code.
using UnityEngine;
using System.Collections;
public class Raycast : MonoBehaviour {
Ray RayOrigin;
RaycastHit HitInfo;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKey(KeyCode.E)){
RayOrigin = Camera.main.ViewportPointToRay(new Vector3(0,0,0));
if (Physics.Raycast(RayOrigin,out HitInfo,100f)){
Debug.DrawRay(RayOrigin.direction,HitInfo.point,Color.yellow);
}
}
}
}