unity Lookat


using ET;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LookatPlayer : MonoBehaviour
{
    CameraComponent cameraCom;
    void Awake()
    {
        cameraCom = Game.Scene.GetComponent<CameraComponent>();
        if (cameraCom == null)
        {
            Debug.LogError("û���ҵ�CameraComponent");
            return;
        }
    }

    // Update is called once per frame
    void Update()
    {
        this.transform.LookAt(cameraCom.CurrCamera.Camera.transform);
       // this.transform.forward = Vector3.forward;
        this.transform.localRotation = Quaternion.Euler(new Vector3(0, this.transform.localRotation.eulerAngles.y, 0));
    }
}

Guess you like

Origin blog.csdn.net/qq_37524903/article/details/123422357