Execution order within the Update() loop method in Unity3D

孤街醉人 提交于 2019-12-06 06:19:48

From Unity's reference manual:

By default, the Awake, OnEnable and Update functions of different scripts are called in the order the scripts are loaded (which is arbitrary). However, it is possible to modify this order using the Script Execution Order settings.

That should solve your problem.

A basic mechanism could be represented by locks.

As an example, let's suppose that A's block depends on B's one. You can control the "dependency" this way:

//B script:
var BLogicPerformed = false;

//...
//Code on which A depends:
function Update(){
    if (BLogicPerformed == false){
        //your operations...
        BLogicPerformed = true;
    }
}

//------------------------------------------------
//A script:

//...
//Code that depends on B:
 function Update(){
    if (this.GetComponent("B").BLogicPerformed == true){
        //Perform logic that depends on B
        this.GetComponent("B").BLogicPerformed = false;
    }
 }

(ugly comparisons with boolean values where just made to keep the code as much clear as I could :-))

I program in Unityscript and, since your question is tagged with both and , I hope that's sufficient for you.

if its only oneway you could use LateUpdate() instead of Update() in one of the scripts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!