让摄像机始终看向某个物体

作者:追风剑情 发布于:2019-6-3 19:35 分类:Unity3d

示例

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

public class CameraLookAt : MonoBehaviour
{
    public bool lookAt = true;
    public Transform target;
    private Transform mTransform;

    void Awake()
    {
        mTransform = transform;
    }

    void Update()
    {
        if (target == null)
            return;
        if (lookAt)
            mTransform.LookAt(target, Vector3.up);
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号