Raycasting

So I know it’s a cardinal sin to use UA as a “give me scripts” kind of thing, but I’m struggling and I figure it will be a simple answer, so maybe it won’t be so bad. I just need an example. If I have a gun, how to start a ray from the gun and go along the x axis of the gun. And if you’re feeling extra nice a Debug.DrawLine to display the ray. I don’t need any hit detection, just an example of how to start/display the ray. and I can do the rest. Thanks :smiley:

From the docs:

function Update() {
    var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    var hit : RaycastHit;
    if (Physics.Raycast (ray, hit, 100)) {
       Debug.DrawLine (ray.origin, hit.point);
    }
}

so if that start from the mouse position on screen, then maybe this is what you need to change. A ray has a starting point (your gun) and a direction (x axis of the gun) which is all you need to modify in this example.