ScrollBackground.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. namespace Plugins.CxShine.ScrollBackgroud
  3. {
  4. public class ScrollBackground : MonoBehaviour
  5. {
  6. public RectTransform mosaique;
  7. [Range(0.001f, 0.01f)] public float speed = 0.001f;
  8. public float lerpDuration = 3;
  9. private Vector2 destination;
  10. private Vector2 startpos;
  11. private float timeElapsed;
  12. // Start is called before the first frame update
  13. private void Start()
  14. {
  15. startpos = mosaique.localPosition;
  16. destination = new Vector2(startpos.x - 100f, startpos.y - 100f);
  17. }
  18. // Update is called once per frame
  19. private void Update()
  20. {
  21. if (timeElapsed < lerpDuration)
  22. {
  23. //mosaique.position = startpos + (Vector3.left * newPos);
  24. mosaique.localPosition = Vector2.Lerp(startpos, destination, timeElapsed / lerpDuration);
  25. timeElapsed += 0.001f;
  26. }
  27. else
  28. {
  29. timeElapsed = 0f;
  30. }
  31. }
  32. }
  33. }