transform.LookAt() Function in Unity
Notes:
transform.LookAt() Function in Unity:
transform.LookAt() method:
- is used to rotate a game object so that its forward vector points at some point or other game object’s transform in one shot
Basic Syntax:
public void LookAt(Vector3 point);
public void LookAt(Transform target);
Example Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CubeController : MonoBehaviour {
public GameObject otherGameObject;
// Use this for initialization
void Start () {
//this.transform.LookAt (new Vector3 (0f, 0f, 0f));
this.transform.LookAt (otherGameObject.transform);
}
// Update is called once per frame
void Update () {
//this.transform.RotateAround (new Vector3 (0f, 0f, 0f), new Vector3 (0f, 1f, 0f), 90f * Time.deltaTime);
this.transform.RotateAround (otherGameObject.transform.position, otherGameObject.transform.up, 90f * Time.deltaTime);
}
}