Camera.ScreenToWorldPoint

Camera.main.ScreenToWorldPoint(Input.mousePosition)

Error: Camera' does not contain a definition for main’

GetComponent().ScreenToWorldPoint(Input.mousePosition)

Error: Type Camera' does not contain a definition for ScreenToWorldPoint’ and no extension method ScreenToWorldPoint' of type Camera’ could be found (are you missing a using directive or an assembly reference?)

This is almost always the result of you creating a script with the name/class of 'Camera', which overrides Unity's Camera script.

1 Answer

1

Make sure you have a reference to your actual camera.

var ScreenPos : Vector2;
Camera.main.ScreenToWorldPoint(ScreenPos);
//Make sure you have one camera tagged 'Main Camera'

or:

public var viewport : Camera; //Assign any camera to this variable
viewport.ScreenToWorldPoint(ScreenPos);