How do we stop the method in unity?
-
Under this violin, the background has to change its form (what it does) but in Enter, there is a computation that finds the difference between the real size and the right and ends only if the difference is zero, which will never occur because of the calculation. Now I have to either forcefully stop the method or somehow implement the completion condition. The problem is that the variable i (the true size of the axis x) is never equal to 2 (numerical size) and is fixed to 1.99999999... (A Change actually comes to a very small Cyber Bowl) Can I do something about it?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems;
public class Button : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[Header("Set manualy")]
[Tooltip("This is the backline, that will be activaited when the mouse is on button")]
public GameObject Background;
[Tooltip("Set how long the line will become, when mouse is on it")]
public float Selected;
public float Speed;
[Header("Sets automatically")]
public RectTransform rt;
public float Change;
public float i;void Awake() { rt = Background.GetComponent<RectTransform>(); i = 1; } public void OnPointerEnter(PointerEventData eventData) { Invoke("Enter", 0f); } void Enter() { print("Still using Enter"); Change = Selected - i; i += Change * Speed; rt.anchorMax = new Vector2(i, 1); if (Change == 0) { Invoke("Enter", 0f);} } public void OnPointerExit(PointerEventData eventData) { Invoke("Exit", 0f); } void Exit() { }
}
-
Problem
float
It's something they have. Read them here: https://ru.stackoverflow.com/q/417453/191482So, as an option, we need to compare.
Change
Not with the exact value of 0, but with some delta you'd like. I mean, for example.if (Change < 0.1)