08
31

 

 

 

일반 오브젝트

using UnityEngine;
using System.Collections;
public class Lookat : MonoBehaviour {
    private Transform Players;
    private Vector3 targetPosition;
    void Start () {
        Players = GameObject.FindGameObjectWithTag ("Player").transform;
    }
    void Update () {
        targetPosition= new Vector3 (Players.position.x, transform.position.y, Players.position.z);
        transform.LookAt (targetPosition);
    }
}

 

월드 캔버스 UI

public class Lookat : MonoBehaviour
{
    private Transform cam;
    void Start()
    {
        cam = Camera.main.transform;
    }
    
    void Update()
    {
        transform.rotation = Quaternion.Euler(cam.rotation.x, cam.rotation.y, cam.rotation.z);
    }
}
COMMENT