1

I have the same scrolling script attached to multiple game objects. But I want them executed in sequence. At present they were executing, I can say randomly so they aren't able to achieve synchronisation with each other in order.

So I want them executed based on each gameobject's order rather then each one randomly selected.

1 Answer 1

1

You can define your own UpdateManually method and call it in the appropriate order yourself. For example:

public class ScrollScriptUpdater : MonoBehaviour
{
    // set references according to desired update order
    // this can be done in the editor or via script if appropriate
    public List<ScrollScript> ScrollScripts;

    void Update ()
    {
        // this updates in the natural order of the list,
        // list item 0, 1, 2, ...
        foreach (var script in ScrollScripts)
        {
            script.UpdateManually();
        }
    }
}

public class ScrollScript : MonoBehaviour
{
    public void UpdateManually()
    {
        // do stuff
    }
}
Sign up to request clarification or add additional context in comments.

3 Comments

No way exist to specify same scripts order in multiple objects ?
@Siddharth I couldn't think of a way without relying on another script to control execution order manually like this.
@Siddharth No, there is no way to tell Unity how to deal with the order of execution of objects beyond the order in which they are created or by creating a script as Sonny has, and doing it manually.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.