- Home /
Button not update()ing,Button not updating
Hi, I have a couple buttons sharing the same script; at various moments they are set active or inactive depending on the user's actions. When they appear, their local positions are reset to (0, 0), and their Update() takes care of putting them back to their initial positions. However, sometimes Update() never gets called at all (checked with a Debug.Log()) and all of the buttons stay at (0, 0). From what I've observed, usually Update() doesn't work until one of the buttons is pressed; the next time they are all updated as normal (and the issue doesn't reappear until the program is restarted). However sometimes it's fine from the start; and sometimes they have to be clicked multiple times until it finally works. I have honestly no clue as to why this is happening. I'm coding for Android, if that helps at all. You can take a look at the script I'm using for my buttons, but I'm guessing there's nothing of particular interest there:
void OnEnable(){
finalPosition = transform.localPosition;
transform.localPosition = Vector3.zero;
}
void OnDisable(){
transform.localPosition = finalPosition;
}
void Update () {
Debug.Log("Update");
transform.localPosition = Vector3.MoveTowards(transform.localPosition, finalPosition, 200.0f*Time.deltaTime);
}
Thanks in advance for any helpful replies. :)
Answer by pekaram · Feb 18, 2018 at 01:11 PM
Check if MonoBehaviour.Enabled is set to true, that's the only reason for Update() not to work.
Your answer
Follow this Question
Related Questions
Buttons remain in pressed state upon performing home interrupt 0 Answers
Animator.Update High CPU Usage on Unity 5 resulting in bugs on Android 0 Answers
GUI button in middle of screen 2 Answers
Holding GUI Button Touch to Rotate Object 0 Answers
how do i use GUI buttons with a android device(tablet) 2 Answers