-2

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 trueor if just bools do not work for any reason int opponentisdeadto 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
        }
Emanuel Graf
  • 756
  • 17
  • 37
  • @sstan please give me a better one and I'll edit immediately – Emanuel Graf May 27 '16 at 19:25
  • Please explain in more detail what way it fails. Decribe the behavior of what happens when you *"try to execute another method, or set a bool or an int to another value,"* Also, Unity does allow you to use a a debugger with scripts. Put a breakpoint in and step through the function, see where the logic goes wrong. – Scott Chamberlain May 27 '16 at 19:29
  • @ScottChamberlain android studio 'attach to proces' recognizes my wifi connected device , but monoDevelop does not. only 'unity editor' to choose. according to http://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html – Emanuel Graf May 27 '16 at 19:50
  • good grief why did everyone downvote this? – Fattie May 27 '16 at 21:00
  • my first instinct is just that "death" is not true for some reason... – Fattie May 27 '16 at 21:03
  • Can you try to tell us when it does and does not work?? – Fattie May 27 '16 at 21:34
  • thank you for those kind words@JoeBlow I'm really sorry if I'm offending someone, I'm trying my best to solve it at my own. Updated my question. – Emanuel Graf May 27 '16 at 22:17
  • Maybe try to do the stuff without the `if(death)` for a test and see if it gets executed. – Gunnar B. May 27 '16 at 23:02
  • @GunnarB. tried it, does not work. as I mentioned, `if (dead)` is true when the problem happens – Emanuel Graf May 28 '16 at 10:01
  • Can you make the three fields public to check them in the inspector on runtime? – Gunnar B. May 28 '16 at 10:11
  • @GunnarB. Did this. I can change the value to 1 / true and it works perfect. what now? – Emanuel Graf May 29 '16 at 22:38
  • You changed them by hand? I meant to just watch them and have a look if they are really not changing. The only further thing to do I would know right now is to set a breakpoint and debug it. – Gunnar B. May 30 '16 at 09:33
  • I have the problem for debugging , my device is not showing up in monodevelop, look a bit up in these comments @GunnarB. – Emanuel Graf May 30 '16 at 14:27

1 Answers1

0

Thanks for your support, I was able to solve it at my own, with a little different way: it works very well, if I change the value of anything of script 1 in script 2 with (script1).instanceMP.opponentisdead = 1;

Emanuel Graf
  • 756
  • 17
  • 37