본문 바로가기
개발/C#

유니티 C# 카메라 이동범위 제한 Camera Mathf.Clamp

by SPNK 2022. 12. 22.
반응형
  • 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    public float offsetX = 10;
    public float offsetY = 10;
    public float offsetZ = 10;


    void LateUpdate()
    {
        transform.position = new Vector3(
            Mathf.Clamp(Camera.main.transform.position.x, -offsetX, offsetX),
            Mathf.Clamp(Camera.main.transform.position.y, -offsetY, offsetY),
            Mathf.Clamp(Camera.main.transform.position.z, -offsetZ, offsetZ));
    }
}

 


참고할만한 글

 

 

유니티 C# 두번 터치로 카메라 줌인 간단 구현 Camera Zoom in

코드 작성 using UnityEngine; public class CameraZoom : MonoBehaviour { public float zoomSpeed = 0.1f; public float minZoom = 1f; public float maxZoom = 10f; private float currentZoom = 1f; void Update() { if (Input.touchCount == 2) { Touch touchZero =

parksh3641.tistory.com

 

 

유니티 C# 카메라 흔들기 Camera Shake 간단 사용법

코드 작성 using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public float shakeAmount = 3.0f; public float shakeTime = 1.0f; private void Start() { S

parksh3641.tistory.com

 

반응형

댓글