1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using UnityEngine;
- using System.Collections.Generic;
- using System;
- /// <summary>
- /// This component is very similar to the HorizontalMovement but is used the loading background
- /// sperms. The velocity is scaled down according to their scale to give the illusion of depth
- /// </summary>T
- public class HorizontalMovementAccordingToScale : MovementBase
- {
- public float minSpeed = 300;
- public float maxSpeed = 600;
- float _speed = 300;
- bool _isSetup;
- void OnEnable()
- {
- //have to delay setup on update due to pooling
- _isSetup = false;
- }
- void Update()
- {
- if (!_isSetup)
- {
- _speed = RandomSingleton.Instance.NextFloat(minSpeed, maxSpeed);
- _speed *= transform.localScale.y; //use the scaling as a factor of speed. The more scaled down == further away == slower
- _isSetup = true;
- }
- float delta = _speed * Time.deltaTime;
- transform.localPosition += new Vector3(delta, 0);
- }
- public override void Encode(List<byte> data)
- {
- data.AddRange(BitConverter.GetBytes(minSpeed));
- data.AddRange(BitConverter.GetBytes(maxSpeed));
- }
- public override void Decode(byte[] data, ref int index)
- {
- minSpeed = BitConverter.ToSingle(data, index);
- index += sizeof(float);
- maxSpeed = BitConverter.ToSingle(data, index);
- index += sizeof(float);
- }
- }
|