유니티 심화

카메라 세팅

다모아 2023. 8. 17. 14:35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowCam : MonoBehaviour
{
    [SerializeField]
    private Transform playerTrans;
    [SerializeField]
    private Transform point;
    [SerializeField]
    private float distance = 10.0f;
    [SerializeField]
    private float height = 2.0f;
    // Start is called before the first frame update
    void Start()
    {
    }

    //Update메서드 이후
    private void LateUpdate()
    {
        //this.transform.position = this.playerTrans.position;
        //연습
        this.point.position = this.playerTrans.position;

        DrawArrow.ForDebug(this.playerTrans.position, this.playerTrans.forward * -1 * this.distance, 10f, Color.blue, ArrowType.Solid);

        var tpos = this.playerTrans.position + this.playerTrans.forward * -1 * this.distance;
        Debug.Log(tpos);

        DrawArrow.ForDebug(tpos, Vector3.up * this.height, 10f, Color.blue, ArrowType.Solid);

        tpos = tpos + Vector3.up * height;

        this.transform.position = tpos;

        this.transform.LookAt(this.playerTrans.position);
    }
}