其他脚本访问时Unity方法不起作用?

我已经制作了一个统一的多人游戏,并且有一个ac#script。 它包含一个方法public void UpdatePlane来更新对手的飞机。
在这个方法中,我想改变一个值( private bool oppdeadtrue或者如果只是private bool oppdead因为任何原因而无法工作, int opponentisdead1 )或者如果我根本不能更改那里的值甚至只是调用方法makeoppdead()来改变那里的价值观。 但究竟那些东西在他们应该的时候不会改变。 我知道在UpdatePlane方法中,死亡变为真,我收到Log ("oppplayer dead is true")但是值没有改变,方法makeoppdead()没有执行,我没有得到日志("method was called") 。 令我惊讶的是,另一方面,它可以毫无问题地改变opponentPrefab Prefab。 这是代码:

  public GameObject opponentPrefab; public Rigidbody2D oppPlane; private bool _multiplayerReady; private string _myParticipantId; private bool oppdead; int opponentisdead = 0; bool boolopponentisdead; float opponentdistance; float distancex; float distancey; float distance; public void UpdatePlane(string senderId, float x, float y, float z, bool death, float oppdistance) { MultiplayerController.Instance.GetMyParticipantId(); opponentdistance = oppdistance; if (death) { //this stuff is NOT being executed: makeoppdead(); opponentisdead = 1; boolopponentisdead = true; //but I do receive this message: Debug.Log("oppplayer dead is true"); } //this stuff is being executed: opponentPrefab = GameObject.Find("Opponent"); opponentPrefab.transform.position = new Vector3(x, y, 0); opponentPrefab.transform.rotation = Quaternion.Euler(0, 0, z); } void makeoppdead() { Debug.Log("method was called"); //do some stuff to provide he is really dead } 

感谢您的支持,我能够以一种不同的方式解决它:如果我用脚本2更改脚本1中任何内容的值,它可以很好地解决它。 (script1).instanceMP.opponentisdead = 1;