diff --git a/Assets/Scenes/Sandbox.unity b/Assets/Scenes/Sandbox.unity index 598c50e..034001b 100644 --- a/Assets/Scenes/Sandbox.unity +++ b/Assets/Scenes/Sandbox.unity @@ -3683,6 +3683,27 @@ Transform: m_CorrespondingSourceObject: {fileID: 8762286023885395322, guid: 9c489a8547f4d9e4387da15a4ff82c81, type: 3} m_PrefabInstance: {fileID: 6782772648210504087} m_PrefabAsset: {fileID: 0} +--- !u!1 &1859157918 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 8616685848737228372, guid: c5efc39a8aaf6e64ea40e9ad573e9b47, type: 3} + m_PrefabInstance: {fileID: 8204767108263278737} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1859157931 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1859157918} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f6b8a4e9bfb741aa96889e5df5a06cba, type: 3} + m_Name: + m_EditorClassIdentifier: + _fovNormal: 40 + _fovZoom: 20 + _camera: {fileID: 1874573760} + _zoomedIn: 0 --- !u!20 &1874573760 stripped Camera: m_CorrespondingSourceObject: {fileID: 9005220659476430821, guid: 2d3a85ecde41a8246a79669975912b74, type: 3} @@ -4029,6 +4050,10 @@ PrefabInstance: propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} + - target: {fileID: 9005220659476430821, guid: 2d3a85ecde41a8246a79669975912b74, type: 3} + propertyPath: field of view + value: 40 + objectReference: {fileID: 0} - target: {fileID: 9005220659476430821, guid: 2d3a85ecde41a8246a79669975912b74, type: 3} propertyPath: far clip plane value: 500 diff --git a/Assets/Weapons/WeaponZoom.cs b/Assets/Weapons/WeaponZoom.cs new file mode 100644 index 0000000..23050f6 --- /dev/null +++ b/Assets/Weapons/WeaponZoom.cs @@ -0,0 +1,40 @@ +using System; +using Cinemachine; +using Unity.VisualScripting; +using UnityEngine; +using UnityEngine.InputSystem; +using Debug = System.Diagnostics.Debug; + +public class WeaponZoom : MonoBehaviour +{ + [Header("Configuration")] + [SerializeField] private float _fovNormal; + [SerializeField] private float _fovZoom; + [Header("State")] + [SerializeField] private CinemachineVirtualCamera _camera; + [SerializeField] private bool _zoomedIn; + + private void OnEnable() + { + _camera = FindObjectOfType(); + Debug.Assert(_camera != null, nameof(_camera) + " != null"); + _fovNormal = _camera.m_Lens.FieldOfView; + } + + private void Update() + { + if (Mouse.current.rightButton.wasPressedThisFrame) + { + _zoomedIn = !_zoomedIn; + } + + if (_zoomedIn) + { + _camera.m_Lens.FieldOfView = _fovZoom; + } + else + { + _camera.m_Lens.FieldOfView = _fovNormal; + } + } +} \ No newline at end of file diff --git a/Assets/Weapons/WeaponZoom.cs.meta b/Assets/Weapons/WeaponZoom.cs.meta new file mode 100644 index 0000000..a74605e --- /dev/null +++ b/Assets/Weapons/WeaponZoom.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f6b8a4e9bfb741aa96889e5df5a06cba +timeCreated: 1665776026 \ No newline at end of file