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;
|
2021-01-11 12:46:46 +01:00
|
|
|
[SerializeField] private Vector2 _xBounds;
|
2021-01-11 11:21:24 +01:00
|
|
|
|
|
|
|
private float _speed;
|
2021-01-11 12:46:46 +01:00
|
|
|
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);
|
2021-01-11 12:46:46 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|