我正在使用放大和縮小相機的腳本,但我已經在游戲中添加了其他相機 pov,所以我試圖使腳本適用于當前選定的相機。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraZoomController : MonoBehaviour
{
private Camera cam;
private float targetZoom;
private float zoomFactor = 2f;
[SerializeField] private float zoomLerpSpeed = 10;
void Start()
{
cam = Camera.main;
targetZoom = cam.orthographicSize;
}
// Update is called once per frame
void Update()
{
float scrollData;
scrollData = Input.GetAxis("Mouse ScrollWheel");
//debug.log(scrollData);
targetZoom = targetZoom - scrollData * zoomFactor;
targetZoom = Mathf.Clamp(targetZoom, 0f, 10f);
cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, targetZoom, Time.deltaTime * zoomLerpSpeed);
}
}
uj5u.com熱心網友回復:
此腳本更新當前相機。start()
在切換游戲攝像機時運行它。
void UpdateCurrent() => cam = Camera.allCameras[Camera.allCamerasCount - 1];
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/475307.html
下一篇:玩家跑步時如何讓跳躍更快?