chenxin
2020-11-14 4a083f2f3d8baf1c2630b3717d62904edcc8e24a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
/**
 * 小怪看向SceneCamera
 * @Author: chenxin
 * @Date: 2020-11-12 17:46:56
 */
namespace KTGMGemClient
{
    public class LookAtSceneCamera : MonoBehaviour
    {
        private Camera sceneCamera;
 
        // Start is called before the first frame update
        private void Start()
        {
            sceneCamera = GameObject.Find("SceneCamera3D").GetComponent<Camera>();
        }
 
        // Update is called once per frame
        private void Update()
        {
 
        }
 
        //Orient the camera after all movement is completed this frame to avoid jittering
        void LateUpdate()
        {
            // transform.LookAt(sceneCamera.transform);
            transform.LookAt(transform.position + sceneCamera.transform.rotation * Vector3.forward,
                sceneCamera.transform.rotation * Vector3.up);
        }
    }
}