Camera script help needed

Hii,

in my scene i have placed a chair, i added a message to check when i click on this object

print(“You hit an object”);
so script is working fine till here

now i want to change the camera position when it hits the object
so my code goes -------

var tagName : String; // allow the designer to make a tag in the inspector
var rayDistance : float = 0; // length of the ray for our raycast

function Update () {

if (Input.GetMouseButtonDown(0))
{
print (“yes the button works”);
var hit : RaycastHit;
var ray : Ray = camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray,hit,rayDistance))
{
if (hit.transform.tag == tagName)
{

print(“You hit an object”);

var position = Vector3(8,1.8,0);
camera.transform.position = position;

}

}

}

}

error::
MissingComponentException: There is no ‘Camera’ attached to the “playerObject” game object, but a script is trying to access it.
You probably need to add a Camera to the game object “playerObject”. Or your script needs to check if the component is attached before using it.
clickOnGameObject.Update () (at Assets/clickOnGameObject.js:19)

what to do ?? shall i have to do something with FPS > Main Camera ??

thanks in advance

There is just a single letter that is incorrect! The line should actually read:-

var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);

“Camera” should be spelt with a capital C. This indicates the name of the Camera class rather than the camera property of the script. If there isn’t a camera component added to the object with the script then using the camera property will give the error you have seen. However, the Camera class is available anywhere and the Camera.main property will find the main camera wherever it is in the scene.

Sir after doing as u guided its again showing, an error

Assets/clickOnGameObject.js(19,8): BCE0020: An instance of type ‘UnityEngine.Component’ is required to access non static member ‘transform’.

i m again posting my entire code::

var tagName : String; // allow the designer to make a tag in the inspector
var rayDistance : float = 0; // length of the ray for our raycast

function Update () {

if (Input.GetMouseButtonDown(0))
{
print (“yes the button works”);
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray,hit,rayDistance))
{
if (hit.transform.tag == tagName)
{
var position = Vector3(8,1.8,0);
Camera.transform.position = position;
print(“You hit an object”);

}

}

}

}