ArgumentException: get_camera can only be called from the main thread.

Hi,
This is the complete Js

var position = camera.WorldToViewportPoint(transform.position);


function OnBecameInvisible ()
{
	gameObject.SetActive(false);
}


function Update ()
{
	if (position.x < -0.1 || position.x > 0.1 || position.y < -0.1 || position.y > 0.1 || position.z < -0.1 || position.z > 0.1)
	{
		OnBecameInvisible ();
	}
}

Now as you can see the title. Unity gives me an error. This is the whole error

ArgumentException: get_camera can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
script01…ctor () (at Assets/Scripts/script01.js:1)

I attached this Js to an object that should be invisible when it’s out of the Camera field view.

SomeOne who can help me out please?

Thanks in advance

Define position variable’s Type, then call it from the main thread.

#pragma strict

var position : Vector3;
 
 
function OnBecameInvisible ()
{
	gameObject.SetActive(false);
}
 
 
function Update ()
{
	position = Camera.main.WorldToViewportPoint(transform.position);
	if (position.x < -0.1 || position.x > 0.1 || position.y < -0.1 || position.y > 0.1 || position.z < -0.1 || position.z > 0.1)
	{
		OnBecameInvisible ();
	}
}