Hi I am adding LookAtCameraYonly.cs in wiki to a Gameobject, I want make it face to camera. but I can’t add it . unity show me this message.
Can anybody tell me where I am wrong?
many thanks!
dongke

Hi I am adding LookAtCameraYonly.cs in wiki to a Gameobject, I want make it face to camera. but I can’t add it . unity show me this message.
Can anybody tell me where I am wrong?
many thanks!
dongke

You need to rename the class in the file to LookAtCameraYonly.
Hi ,I think I did it.
using UnityEngine;
using System.Collections;
public class LookAtCameraYonly : MonoBehaviour
{
public Camera cameraToLookAt;
void Update()
{
Vector3 v = cameraToLookAt.transform.position - transform.position;
v.x = v.z = 0.0f;
transform.LookAt(cameraToLookAt.transform.position - v);
}
}
Is the file named LookAtCameraYonly?
C# needs file name and class name to match.
OU, It works now, my mistake here.
thankyou very much for replying,
but I still have another question.
If I have 3 cameras in a scene I already made swich between them in a empty GameObject , then how can I make a object always look at camera, even the camera is switched between these 3 cameras?
thanks again.