Re-position and Look at.
Hi there, I'm trying to get the camera to return to an original starting point on a keypress by putting this code on it. The camera returns to the specified point alright but doesn't look at the object in the variable. How can I get it to do this?
#pragma strict
public var target: Transform;
function Update () {
if (Input.GetKeyDown(KeyCode.F1))
{
transform.position = Vector3(0, 0, -4);
transform.LookAt(target);
}
}
Answer by IHackedDeath · Sep 09, 2015 at 10:06 AM
Hi Daniel Talis,
I have read through your question and can see a few things that should help.
First of all, I know you stated that returning to the original position works but I thought I might add another way of returning to the starting point that might help a bit more.
If you declare a variable Vector 3 called original position (or whatever you feel like naming it) and save the camera's position to it in the start function then you can refer to it at any point in the game without having to worry about where it actually is in world space.
Second, have you declared the target variable in the editor?
It honestly looks like it should work fine so just double check if there is anything actually in the target area in the editor where the script is attached.
I hope this helps.
Kind Regards,
IHackedDeath.