How do I get my object to move towards the mouse without using raycasts or transform?

Hello! I wrote out some code for this problem, but I’m new to programming in unity and feel like I made a simple error but can’t seem to locate it. 122067-helperror.png

I’d prefer to not use raycast’s or transform because I’d like the object to maintain momentum from the simple physics system attached to it. I think the error may be attached to the “GetComponent().position” but am not sure how to reference the attached objects position (Also the error in unity just references the whole block starting at Input.GetMouseButton(0))
Thank you in advance!

Good day.

I dont give you the answer, i show you the doors you must explore, and some tips:

First, Declare the variables Camera and the 3 floats at the Start() method, as only need to be done once, no need to do every frame you are entering this part of the code… is not a good practice for memory issues.

Second, expolore this: Unity - Scripting API: Camera.ScreenToWorldPoint

Third, You need transform for moving something. All objects in the scene ARE a transform, it means a position a rotation and a scale, so you need to use it. You have so many ways to do it.

transform.position += new Vector3 (0,1,0);

And using phisycs, by adding forces to the rigidbody.

Go learn!