shoot to the mouse cursos

Hey guys im trying to do a 2d game shooter ( not spirit, 3d aspect ) , and im trying to change a shooting script where instead of shooting forward , i shoot toward the mouse cursos but i get errors ,here what i tried

function shoot () {
   var Hit : RaycastHit; 
       var DirectionRay = transform.TransformDirection(Vector3.forward); // <== (the part i want to change)

        Debug.DrawRay (transform.position ,DirectionRay * Range ,;
       if (Physics.Raycast(transform.position , DirectionRay , Hit, Range)){
          if (Hit.rigidbody){
              Hit.rigidbody.AddForceAtPosition ( DirectionRay * Force , Hit.point);
              Hit.collider.SendMessageUpwards("ApplyDamage" , Damage, SendMessageOptions.DontRequireReceiver);

i tried with:

var Directionay = Camera.main.ScreenPointToRay (Input.mousePosition );

but didn’t work lots of methode errors =(

put it back how it was. the line you took out works fine. your getting an error cause your feeding raycast to much info. saying Camera.main.ScreenPointToRay (Input.mousePosition ) gives the raycast all the info it needs.

just say:

if (Physics.Raycast(DirectionRay , Hit, Range)){}

without the “transform.position” part and you wont get errors. raycast format is only one point and one direction. so the first ray is a line from camera THROUGH mouse.
if you want a direction for your bullet, your variable “Hit” contains the location of the mouse.
you can pull a vector three out of it by saying hit.point.

the “hit” varaible is what the mouse clicked on. not your bullet.

hey i was thinking of a new way to make my dream shoot a reality. should i let the raycast script as before( streght line) and instead make the spawn point (empty game Object ) rotate towards the mouse would it be more easy or the post way is more easyer?