Select your preferred scripting language. All code snippets will be displayed in this language.
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Closetarget | Object to point towards. |
worldUp | Vector specifying the upward direction. |
Rotates the transform so the forward vector points at /target/'s current position.
Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp
vector.
If you leave out the worldUp
parameter, the function will use the world y axis.
worldUp
is only a hint vector. The up vector of the rotation will only match the worldUp
vector if the forward direction is perpendicular to worldUp
.
#pragma strict
// This complete script can be attached to a camera to make it
// continuously point at another object.
// The target
variable shows up as a property in the inspector.
// Drag another object onto it to make the camera look at it.
public var target: Transform;
function Update() {
// Rotate the camera every frame so it keeps looking at the target
transform.LookAt(target);
}
// This complete script can be attached to a camera to make it // continuously point at another object.
// Thetarget
variable shows up as a property in the inspector. // Drag another object onto it to make the camera look at it. using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public Transform target;
void Update() { // Rotate the camera every frame so it keeps looking at the target transform.LookAt(target); } }
worldPosition | Point to look at. |
worldUp | Vector specifying the upward direction. |
Rotates the transform so the forward vector points at worldPosition
.
Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp
vector.
If you leave out the worldUp
parameter, the function will use the world y axis.
worldUp
is only a hint vector. The up vector of the rotation will only match the worldUp
vector if the forward direction is perpendicular to worldUp
.
// Point the object at the world origin transform.LookAt(Vector3.zero);
using UnityEngine;
public class ExampleClass : MonoBehaviour { public Transform target;
void Update() { // Point the object at the world origin transform.LookAt(Vector3.zero); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information