Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Limited updates?

Discussion in 'Scripting' started by TheKrazyDev, Mar 8, 2022.

  1. TheKrazyDev

    TheKrazyDev

    Joined:
    Sep 8, 2021
    Posts:
    107
    OK so I'm pretty new to C# but have experience with bolt. And I wasn't sure but can you only have 1 update event in a script? Really short question, but I wasn't sure.
     
  2. gdosu

    gdosu

    Joined:
    Aug 24, 2020
    Posts:
    13
    Hello. The question is too vague. Can you explain it in more detail?
     
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    If you're referring to something like:

    Code (csharp):
    1. public class MyScript : MonoBehaviour
    2. {
    3.  
    4.     void Update()
    5.     {
    6.         //this being the Update event
    7.     }
    8.  
    9. }
    Yes, you can only have 1 in your script.

    If you want to have multiple methods that are called during Update. Just implement them and then call them from Update:
    Code (csharp):
    1. public class MyScript : MonoBehaviour
    2. {
    3.  
    4.     void Update()
    5.     {
    6.         UpdateAlt1();
    7.         UpdateAlt2();
    8.     }
    9.  
    10.     void UpdateAlt1()
    11.     {
    12.     }
    13.  
    14.     void UpdateAlt2()
    15.     {
    16.     }
    17.  
    18. }
     
    Bunny83 likes this.
  4. TheKrazyDev

    TheKrazyDev

    Joined:
    Sep 8, 2021
    Posts:
    107
    Thanks.