click object and move the cam in ur desired x,y,z coordinates..what am i doing wrong

Hii,

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

so it prints prefect

print(“You hit an object”);

now i want to change the camera position when it hits the object

to see whats happening, u can also see my screen cast ::
http://www.screencast-o-matic.com/watch/cXhOXMF3r

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);

var getFPScam = GameObject.Find("FPScam");
getFPScam.transform.position = position;

//camera.main.transform.position = position;

var getFPS = GameObject.Find("FPS");
getFPS.transform.position = position;

}

}

}

}

problem coming is strange - my camera leaves my fps body when i click the object, here is the package if u want to download n see

Hi,
In your script you determine the whether an object was mouse clicked and then you move your first persion shooter camera to some place (8,1.8, 0) later you move the FPS prefab to the same position. However as your camera is a child of the FPS you have introduced an offset between the camera and the FPS. What you should do is move the whole fps to the position, not the camera alone, and the camera will follow as it is a child of the FPS.

Hope this helps.

rightly said…its working fine this way…thanks