Example #1
0
        public void Update()
        {
            // Toggle motors

            if (Input.GetKeyDown(KeyCode.T))
            {
                foreach (MotorWheel motor in FindObjectsOfType <MotorWheel>())
                {
                    Type          typ  = typeof(MotorWheel);
                    FieldInfo     type = typ.GetField("network", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    Semih_Network net  = (Semih_Network)type.GetValue(motor);


                    Message_NetworkBehaviour_ID message = new Message_NetworkBehaviour_ID(Messages.MotorWheel_PowerButton, net.NetworkIDManager, motor.ObjectIndex);

                    if (Semih_Network.IsHost)
                    {
                        motor.ToggleEngine();
                        net.RPC(message, Target.Other, EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game);
                    }
                    else
                    {
                        net.SendP2P(net.HostID, message, EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game);
                    }
                }
            }

            // Change direction

            if (Input.GetKeyDown(KeyCode.Y))
            {
                foreach (MotorWheel motor in FindObjectsOfType <MotorWheel>())
                {
                    Type          typ  = typeof(MotorWheel);
                    FieldInfo     type = typ.GetField("network", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                    Semih_Network net  = (Semih_Network)type.GetValue(motor);


                    Message_NetworkBehaviour_ID message = new Message_NetworkBehaviour_ID(Messages.MotorWheel_Inverse, net.NetworkIDManager, motor.ObjectIndex);

                    if (Semih_Network.IsHost)
                    {
                        motor.InversePushDirection();
                        net.RPC(message, Target.Other, EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game);
                    }
                    else
                    {
                        net.SendP2P(net.HostID, message, EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game);
                    }
                }
            }
        }
Example #2
0
 public static void ToggleAllEnginesDir()
 {
     if (network == null)
     {
         network = ComponentManager <Semih_Network> .Value;
     }
     foreach (MotorWheel motor in FindObjectsOfType <MotorWheel>())
     {
         Message_NetworkBehaviour_ID message = new Message_NetworkBehaviour_ID(Messages.MotorWheel_Inverse, network.NetworkIDManager, motor.ObjectIndex);
         if (Semih_Network.IsHost)
         {
             motor.InversePushDirection();
             network.RPC(message, Target.Other, EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game);
             continue;
         }
         network.SendP2P(network.HostID, message, EP2PSend.k_EP2PSendReliable, NetworkChannel.Channel_Game);
     }
 }