Good day. There was a problem with the creation of the main menu for the game. I have 2 objects: Game Name and Buttons (containing 4 thumbnails). General structure: enter image description here

Parameters of objects and their Rect Transform:

enter image description here

enter image description here enter image description here

A scrolling script is attached to the Buttons and GameText object:

public class ScrollObjects : MonoBehaviour { public float speed = 5f, checkPos = 0f; private RectTransform rect; void Start() { rect = GetComponent<RectTransform>(); } void Update() { if (rect.offsetMin.y != checkPos) rect.offsetMin += new Vector2(rect.offsetMin.x, speed); rect.offsetMax += new Vector2(rect.offsetMax.x, speed); } } 

The question is why the buttons do not stop at the 0th value and continue to move up? The same thing happens with GameName (if you change the speed to -5f because it should float from top to bottom). PS In the screenshots, I did not take the initial position of the objects beyond the limits of visibility, but even with such parameters, when launching, the objects simply run up. Sorry for the crumpled question, I tried to describe as I could, if I need additional information, I will share it.

    2 answers 2

    In if you use! =, And you need to use comparison signs (>> = <<=, depending on your logic). float variable you do not get an absolute zero, read about accuracy. Here you can read.

    • Yes, the comparison was not superfluous. But beyond that, it was necessary to add an action in brackets, after the condition. - Denis Klimkov pm

    For a beautiful menu, you can use the DoTween asset. There is a free version and it is quite simple to make a menu on it and at the same time it is quite beautiful.