Find Camera atuomatically

I need help with this code:


//var thetarget : Camera.main;

var cam : Camera = GameObject.Find("Main Camera");

function Update() 

{ 
   transform.LookAt(transform.position + cam.forward);
}

The issue that I am having is that on my spawned enemies the camera is lost if I uncomment the first line and set the camera. but i want it to find the main camera automatically…

i get an error with the above in that : BCE0019: ‘forward’ is not a member of ‘UnityEngine.Camera’.

does this make sense?

put this line up the top of your file

private var theCam:Camera;

Next look at and click the actual camera in your Hierarchy panel.

You must rename the camera to happyCam

Finally, put this line as the first line in your Awake() routine

theCam = GameObject.Find("happyCam").GetComponent(Camera);

Now you’re all set. refer to the camera as “theCam”