반응형
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 | 2-5 CameraFollow using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraFollow : MonoBehaviour { public Transform target; // The position that that camera will be following. public float smoothing = 5f; // The speed with which the camera will be following. Vector3 offset; // The initial offset from the target. void Start() { // Calculate the initial offset. offset = transform.position - target.position; } void FixedUpdate() { // Create a postion the camera is aiming for based on the offset from the target. Vector3 targetCamPos = target.position + offset; // Smoothly interpolate between the camera's current position and it's target position. transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime); } } | cs |
반응형
'etc-posts > Unity :: C# 튜토리얼' 카테고리의 다른 글
[유니티C#][AR] 누르면 색변하는 차 만들기.1 (0) | 2019.01.12 |
---|---|
[유니티C#][기초] 17. 튜토리얼 SurvivalShooter 정리.6 (0) | 2018.07.14 |
[유니티C#][기초] 15. 튜토리얼 SurvivalShooter 정리.4 (0) | 2018.07.14 |
[유니티C#][기초] 14. 튜토리얼 SurvivalShooter 정리.3 (0) | 2018.07.08 |
[유니티C#][기초] 13. 튜토리얼 SurvivalShooter 정리.2 (0) | 2018.07.08 |