[C#]I can't figure out how to instantiate a prefab just out the right of my screen

Challenges to keep in mind;

  • The camera is the default, ortho cam. Size is kept at default 5.
  • The camera is most likely not going to be zooming in/out, but it might eventually.
  • Players can play at different resolutions and ratios.

So basically, I’ve got a prefab named Target. It’s 64x64 with a rigid2Dbody and a 2D collision box.

Then I have a TargetsMngr with a TargetMngrScript inside of it that is as follow;

Line 23 is my failed attempt.

Basically, I’m making a shooter. Enemies fly in from the right side and you have to shoot them before they reach the left side. Easy as. I just want to make sure they are instantiated OUTSIDE the right side before they start moving towards the left, regardless of what resolution/ratio/etc the user is using.

I’ve got the biggest headache.

Got it.

screenSize = Camera.main.ViewportToWorldPoint (new Vector3 (1.0f, 1.0f, 0.0f));