Trying to adapt shoot to my game

hi foks, i’m trying to add a shot from another tutorial to my “game” unfortunately the command take input from the camera view to detect target of fire, and i need a straigth foward bullet,

i’ve tried everything, vector3 stuff etc… but i’m new to C++ and unity,

any help is welcome,

thanks a lot,

using UnityEngine;
using System.Collections;

public class PlayerShooting : MonoBehaviour
{

public Projectile projectilePrefab;
public LayerMask mask;

Camera camera;

void Update()
{
bool mouseButtonDown = Input.GetMouseButtonDown(0);
if (mouseButtonDown)
{
raycastOnMouseClick();
}
}

void raycastOnMouseClick()
{
RaycastHit hit;
Ray rayToFloor = Camera.main.ScreenPointToRay(Input.mousePosition);

if (Physics.Raycast(rayToFloor, out hit, 100.0f, mask, QueryTriggerInteraction.Collide))
{
shoot(hit);
}
}

I have look on my move routine, and found a couple of data who can help to locate the origin of the fire, and put it to foward, but nothing is displayed

Ray rayToFloor = new Ray(new Vector3(currentPosition.x, currentPosition.y, currentPosition.z), transform.forward);

thanks for any help

Uhhh C#.

This seems fine.
Add a Debug.DrawRay so that you can see it in the editor:

Just make sure to get the Cameras position and use transform.forward in a Ray so that it goes from the center of the screen, forward.

yes i’m sorry i know its c#, the debug draw work, that make a green ray on the scene but this make only a ray green,

I focus to make a small game shooter and found some usefull code here : https://www.raywenderlich.com/127672/introduction-unity-scripting

(have purchased the book got it tomorrow ; ))))

i dont understood how to code a pure vector of 20 pixel straigth foward from the origin of my plane who is currentposition.x in my tweaked move script.

Vector3 currentPosition = transform.position;
pos_x = currentPosition.x;

these coordinate work in Move.cs but not in the PlayerShooting.cs (show in above link)

the script of origin work but put the destination of the ray as mouse input

void raycastOnMouseClick () {
RaycastHit hit;
Ray rayToFloor = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.DrawRay(rayToFloor.origin, rayToFloor.direction * 100.1f, Color.red, 2);

if(Physics.Raycast(rayToFloor, out hit, 100.0f, mask, QueryTriggerInteraction.Collide)) {
shoot(hit);
}
}

I have worked on the doc but that style confuse,

any help is welcome, perhaps the book will answer this

thanks a lot