Skip to content
Snippets Groups Projects
Commit 9b3c0201 authored by Adrian Paschkowski's avatar Adrian Paschkowski :thinking:
Browse files

Basic camera zoom + multiple background segments

parent 83ee72de
No related branches found
No related tags found
No related merge requests found
fileFormatVersion: 2
guid: 7354282c08adc7140aa1a431220c8dde
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: bc9ce5621538414418f955a3f6c18ca3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 0d731b3310804d246934a98d644ffd6e
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: 21f9110dbc1cca4468db62b14192f7b0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BaseCameraController : MonoBehaviour
{
[Header("Zoom")]
[SerializeField] float maxZoom = 5f;
[SerializeField] float minZoom = 1.5f;
[SerializeField] float zoomStepSize = 1f;
[SerializeField] float zoomDuration = 0.1f;
Interpolator zoomInterpolator;
new Camera camera;
new AudioSource audio;
void Awake()
{
camera = GetComponent<Camera>();
audio = GetComponent<AudioSource>();
zoomInterpolator = new Interpolator(zoomDuration, camera.orthographicSize, camera.orthographicSize, minZoom, maxZoom);
}
void Update()
{
var inputZoomDelta = Input.mouseScrollDelta.y * -zoomStepSize;
if (inputZoomDelta != 0)
{
zoomInterpolator.targetValue += inputZoomDelta;
}
camera.orthographicSize = zoomInterpolator.GetCurrentValue();
}
public void PlayGlobalAudioClip(AudioClip clip, float volume = 1f)
{
audio.PlayOneShot(clip, volume);
}
}
fileFormatVersion: 2
guid: 4471af6bb2e057546a362ad75c91f770
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Interpolator
{
public float targetValue
{
get => _targetValue;
set
{
_targetValue = Mathf.Clamp(value, minValue, maxValue);
running = true;
}
}
private float duration;
private float minValue;
private float maxValue;
private float currentValue;
private float _targetValue;
private float velocity;
private bool running = true;
public Interpolator(float duration) : this(duration, 0)
{
}
public Interpolator(float duration, float startValue) : this(duration, startValue, startValue)
{
}
public Interpolator(float duration, float startValue, float targetValue) : this(duration, startValue, targetValue, float.NegativeInfinity, float.PositiveInfinity)
{
}
public Interpolator(float duration, float startValue, float targetValue, float minValue, float maxValue)
{
this.duration = duration;
this.minValue = minValue;
this.maxValue = maxValue;
currentValue = startValue;
_targetValue = targetValue;
if (Mathf.Approximately(startValue, targetValue))
{
running = false;
}
}
public float GetCurrentValue()
{
if (running)
{
currentValue = Mathf.SmoothDamp(currentValue, _targetValue, ref velocity, duration);
if (Mathf.Abs(velocity) < 0.001f)
{
running = false;
currentValue = targetValue;
}
}
return currentValue;
}
}
fileFormatVersion: 2
guid: 35a98a77f17dfcf4fb8195f4bc6eba69
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -41,3 +41,9 @@ TagManager:
- name: Default
uniqueID: 0
locked: 0
- name: Player
uniqueID: 3566149241
locked: 0
- name: OccludesPlayer
uniqueID: 2463568037
locked: 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment