12345678910111213141516171819202122232425262728293031 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is used by the background loading sperms and is responsible for putting
- /// them further away from the camera according the scale, to give proper depth
- /// </summary>
- public class AdjustZAccordingToScale : MonoBehaviour
- {
- public float nearZ = 1;
- public float farZ = 10;
- bool _isSetup;
- void OnEnable()
- {
- //have to delay setup on update due to pooling
- _isSetup = false;
- }
- void Update()
- {
- if (!_isSetup)
- {
- float percentageScaled = Mathf.Lerp(LoadingBackgroundSpermsManager.MAX_SCALE, LoadingBackgroundSpermsManager.MIN_SCALE, transform.localScale.y);
- Vector3 pos = transform.localPosition;
- pos.z = Mathf.Lerp(nearZ, farZ, percentageScaled);
- transform.localPosition = pos;
- _isSetup = true;
- }
- }
- }
|