Question by
MakeMeASandwich · Dec 08, 2015 at 06:52 PM ·
c#cameralookat
"Lookat" only working in one case
Hello,
I'm having this problem with the "Lookat" function, I have it in a script that is used multiple times for sets of game objects. In the script, each sub set has a main collider for the camera to "Lookat". However, when you run the game, it only looks at one of the game objects sets it is attached to. In the debug.log sections where it is logging the cameras rotation, it says it is rotating to the position but in the game window it stays in the starting position(where the is looking first). There are pictures of the problem in action
Here is the code for the camera rotation
void Start ()
{
cam = Camera.main.GetComponent<Camera>();
start_postion = cam.transform.rotation;
}
// Update is called once per frame
void Update ()
{
if(part_selected)
{
if(Input.GetKeyUp(KeyCode.RightArrow))
{
last_part = indexed_part;
indexed_part++;
if(indexed_part >= total_num_of_parts)
{
indexed_part -= total_num_of_parts;
}
}
cam.transform.LookAt(gameObject.transform.position);
Debug.Log("Looking at" + cam.transform.rotation);
cam.fieldOfView = zoomed_fov;
if(Input.GetKeyDown(KeyCode.Escape))
{
part_selected = false;
}
}
else
{
Debug.Log("In else for " + gameObject);
cam.transform.rotation = start_postion;
cam.fieldOfView = normal_fov;
}
all_parts[last_part].SetActive(false);
all_parts[indexed_part].SetActive(true);
Debug.Log("End of script" + cam.transform.rotation);
}
void OnMouseDown()
{
Debug.Log("Mouse clicked on " + gameObject);
part_selected = true;
}
capture.png
(108.2 kB)
capture2.png
(104.0 kB)
Comment