lucid-super-dream/Assets/Scripts/SlideSideways.cs

40 lines
965 B
C#
Raw Normal View History

2021-01-11 11:21:24 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class SlideSideways : MonoBehaviour
{
[SerializeField] private Vector2 _speedRange;
[SerializeField] private Vector2 _xBounds;
2021-01-11 11:21:24 +01:00
private float _speed;
private float _xDiff;
private void Awake()
{
_xDiff = _xBounds.y - _xBounds.x;
}
2021-01-11 11:21:24 +01:00
private void Start()
{
var r = new Unity.Mathematics.Random((uint)(Time.time*1000f));
_speed = r.NextFloat(_speedRange.x, _speedRange.y);
}
private void LateUpdate()
{
transform.Translate(Vector3.right * _speed * Time.deltaTime);
if (transform.position.x < _xBounds.x)
{
transform.position += Vector3.right * _xDiff;
}
else if (transform.position.x > _xBounds.y)
{
transform.position -= Vector3.right * _xDiff;
}
2021-01-11 11:21:24 +01:00
}
}