- Home /
Define execution order of same script on multiple gameobjects
I have same scrolling script attached on multiple game objects. But I want they executed in sequence. At present they were executing, I can say randomly so they can't able to achiever synchronisation with each other in order.
So I want they executed based on each gameobject's order rather then each one randomly selected. Please give me some help into this.
Answer by Koyemsi · May 17, 2018 at 11:31 AM
Hi. I think one way to do this would be to make an object working like a level manager, in order to control the execution order. So you would have an empty GO with a script (the level manager) where you would store a List of all your scrolling GOs. This manager would sequentially control these objects, by allowing their script, or calling their scrolling method at the right moment.
Yes I understand your point but what if I want to assign individual script to each gameobject. Any way possible for this ?
No problem, as far as I understand what you mean exactly. In my idea, each of your GOs has its own individual script (the scrolling script). The level manager GO would only list these GOs, and activate their scrolling scripts in the order you defined. Or am I missing something ?
Answer by KaspianR · May 17, 2018 at 11:55 AM
I think you could just move your code to another function
public void FunctionName(){
//code goes here
}
Then you can just make another script and put it on empty GameObject. The script should look something like this:
public YourScriptName[] scripts;
void Update(){
foreach(YourScriptName script in scripts){
script.FunctionName();
}
}
Now, just add the scripts to the Array in the order you wan't them to be executed and it should work!
If you wan't to more easily edit the order during runtime replace the first line in the second script with:`public List scripts;` I would actually recommend a List ins$$anonymous$$d since they are easier to work with overall!
Yes I am getting your point clearly :) Let me try to implement and check...
Thank for your side quick reply.
You both talking about same point so I have up voted your answer and marked as correct first replied answer... Please keep supporting always..
Thanks for the vote. I've also upvoted @$$anonymous$$aspianR because its answer would also deserve to be "best answer".
Your answer
Follow this Question
Related Questions
Problems with a quad dimensions 0 Answers
The position of the object and its changes! Help me can not understand! 0 Answers
Rotate Method via Update ? 2 Answers
future updates 0 Answers