I have made a multiplayer game in unity, and have a c# script. It contains a method public void UpdatePlane
to update the opponents plane.
Inside this method, I want to change a value (private bool oppdead
to true
or if just bools do not work for any reason int opponentisdead
to 1
) or if I cant change values in there at all even just call the methodmakeoppdead()
to change the values there. but exactly those things do not change when they should. I know when inside the method UpdatePlane
, death becomes true, I receive the Log ("oppplayer dead is true")
but the values doesnt change and the methodmakeoppdead()
is not beeing executed, I'm not getting the log("method was called")
. Surprisingly for me, on the other hand, it can transform the opponentPrefab
without any problems. here's the code:
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
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…