//********************************************************// // // // Copyright © All rights reserved. MyNameIsVoo. 2020. // // // // COPYING FORBIDEN // // // //********************************************************// using UnityEngine; /// /// Sway background or camera - it's easy /// namespace ICWM { namespace Utility { public class SwayCamera : MonoBehaviour { [Header("ATTRIBUTES")] [SerializeField] private float amount = 5f; [SerializeField] private float maxAmount = 10f; [SerializeField] private float smoothMouseLook = 3f; private Vector3 startPosition; private void Start() { startPosition = transform.localPosition; } private void Update() { float factorX = -Input.GetAxis("Mouse X") * amount; float factorY = -Input.GetAxis("Mouse Y") * amount; if (factorX > maxAmount) factorX = maxAmount; else if (factorX < -maxAmount) factorX = -maxAmount; if (factorY > maxAmount) factorY = maxAmount; else if (factorY < -maxAmount) factorY = -maxAmount; Vector3 final = new Vector3(startPosition.x + factorX, startPosition.y + factorY, startPosition.z); transform.localPosition = Vector3.Lerp(transform.localPosition, final, Time.deltaTime * smoothMouseLook); } } } }