camera follow object

hi guys i m trying to make camera follow object.

i could manage to make camera follow my object with manually attaching but i want to make that object connect automatically in script.

for example i have cube in my scene n i want my cam to transform.lookat to that object automatically.

can someone plz give me some example how i can do that tks a lit inadvace.

you have to get a reference of that object, one easy way is to put a tag on it such as player then if you have a target variable on the camera then make it find it by tag as example:

target = GameObject.FindWithTag(“Player”).transform; that is assuming that the target variable is a transform type.
keep in mind this is pseudo code so i might of mispelled it, if you copy and paste it might not work. so make shure you have it typed correctly.

hi tks a lot for the reply
can i use something like as well?
target = GameObject.Find(“targetLookAt”) as GameObject;

targetLookAt as a empty game object parented to the character.

tks