Version: 5.3 (switch to 5.4b)
ЯзыкEnglish
  • C#
  • JS

Язык программирования

Выберите подходящий для вас язык программирования. Все примеры кода будут представлены на выбранном языке.

Transform.LookAt

Предложить изменения

Успех!

Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.

Закрыть

Ошибка внесения изменений

По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.

Закрыть

Отменить

Руководство
public function LookAt(target: Transform, worldUp: Vector3 = Vector3.up): void;
public void LookAt(Transform target, Vector3 worldUp = Vector3.up);
public function LookAt(target: Transform, worldUp: Vector3 = Vector3.up): void;
public void LookAt(Transform target, Vector3 worldUp = Vector3.up);

Параметры

target 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.


        
	// 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.
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); } }

public function LookAt(worldPosition: Vector3, worldUp: Vector3 = Vector3.up): void;
public void LookAt(Vector3 worldPosition, Vector3 worldUp = Vector3.up);
public function LookAt(worldPosition: Vector3, worldUp: Vector3 = Vector3.up): void;
public void LookAt(Vector3 worldPosition, Vector3 worldUp = Vector3.up);

Параметры

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);
	// Point the object at the world origin
	transform.LookAt(Vector3.zero);