added bonus and side moving obstacle

This commit is contained in:
MrTorex committed 2026-03-08 10:29:09 +03:00
1 parent 08e050ffd3
commit e039461a83
17 files changed
+1171 -11

No files matched your search

@@ -0,0 +1,39 @@
using UnityEngine;
namespace Code.Gameplay.Level
{
public class SideMovingObstacle : MonoBehaviour
{
public float speed = 10f;
[SerializeField] private float range = 7f;
private bool _movingRight;
private void Start()
{
_movingRight = transform.position.x < 0;
UpdateRotation();
}
private void Update()
{
var step = speed * Time.deltaTime;
transform.Translate(Vector3.forward * step);
if (_movingRight && transform.position.x >= range)
{
_movingRight = false;
UpdateRotation();
}
else if (!_movingRight && transform.position.x <= -range)
{
_movingRight = true;
UpdateRotation();
}
}
private void UpdateRotation()
{
transform.rotation = Quaternion.Euler(0, _movingRight ? 90 : -90, 0);
}
}
}