What am i doing wrong here?

Hi, i’m VERY new to Unity. Like i started just now. :stuck_out_tongue:

So i’m trying to make a turret of a tank rotate towards a point in the world. This point is defined by my mouse cursor on the screen which is then converted to a world point.

I’m working in a 3D space, even though it’s a 2D game i’m making. The reason for that is because it’s a school project and there has to be an ability to to toggle between perspective and orthographic mode. Even though perspective mode would obviously render my screen to world mouse position useless, i still want to try and get this to work for “reasons”.

So what i did was look up some info regarding this technique and what i found was a post by someone that pretty much came down to the following piece of code.

Vector3 _target = Camera.main.ScreenToWorldPoint(Vector3(0,0,0));

Now when i go into Unity it gives me a compile error.

“Expression donates a ‘type’, where a ‘variable’, 'value or ‘method’ was expected.”

Now as i said, this is probably an extremely newbie question. But keep in mind i’m very new to programming in general. I do have a tiny bit of c++ programming behind me, but that’s about it.

It should be:

Vector3 _target = Camera.main.ScreenToWorldPoint(new Vector3(0,0,0));


Vector3 _target = Camera.main.ScreenToWorldPoint(Vector3.zero);

The function expects a value, so you have to create one (with the new keyword), use an existing one (an already created variable, like Vector3.zero or another Vector3 you already have created or obtained), or a method that returns a Vector3.

Yes indeed! I just found out from another website. But thanks! :smiley:

Vector3 _target = new Vector3(0,0,0);