Ejemplo n.º 1
0
    void HandleFiring()
    {
        // If you press the fire key, or when you are still firing
        if ((!firing && Input.GetKeyDown(Options.Controls.Fire)) || (firing && fireTimer >= 20))
        {
            if (!startFiringPackageSent)
            {
                startFiringPackageSent = true;

                FireWeaponPackage fwp = new FireWeaponPackage();
                fwp.Enabled = true;
                fwp.Target  = GetComponentInChildren <Camera>().transform.rotation.eulerAngles.x;
                NetworkManager.Instance.Client.SendData(fwp);

                Fire();
            }
        }
        else if (firing && !Input.GetKey(Options.Controls.Fire))
        {
            if (!stopFiringPackageSent)
            {
                stopFiringPackageSent = true;
                FireWeaponPackage fwp = new FireWeaponPackage();
                fwp.Enabled = false;
                fwp.Target  = GetComponentInChildren <Camera>().transform.rotation.eulerAngles.x;
                NetworkManager.Instance.Client.SendData(fwp);
            }
        }
    }
Ejemplo n.º 2
0
        public override DataPackage CreateFromBody(string b)
        {
            string[] split = b.Split('|');

            FireWeaponPackage fwp = new FireWeaponPackage();
            fwp.Enabled = bool.Parse(split[0]);
            fwp.Target = float.Parse(split[1]);
            return fwp;
        }
Ejemplo n.º 3
0
        public override DataPackage CreateFromBody(string b)
        {
            string[] split = b.Split('|');

            FireWeaponPackage fwp = new FireWeaponPackage();

            fwp.Enabled = bool.Parse(split[0]);
            fwp.Target  = float.Parse(split[1]);
            return(fwp);
        }
Ejemplo n.º 4
0
    public void OnDataReceived(DataPackage dp)
    {
        if (dp is TokenChangePackage)
        {
            if (sendCounter == 1)
            {
                resend      = true;
                sendCounter = 0;
            }
            else
            {
                sendCounter++;
            }
        }
        else if (dp is PlayerMovePackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            PlayerMovePackage pmp = (PlayerMovePackage)dp;

            if (!pmp.RotationOnly)
            {
                //set position
                transform.root.position = pmp.Position;

                //set rotation
                float newRotX = pmp.Rotation.x - transform.root.rotation.eulerAngles.x;
                float newRotY = pmp.Rotation.y - transform.root.rotation.eulerAngles.y;
                float newRotZ = pmp.Rotation.z - transform.root.rotation.eulerAngles.z;
                transform.root.Rotate(newRotX, newRotY, newRotZ);

                //set direction
                if (pmp.Dir.Has(PlayerMovePackage.Direction.Stop))
                {
                    anim.SetFloat("Speed", 0);
                }
                if (pmp.Dir.Has(PlayerMovePackage.Direction.Up))
                {
                    anim.SetFloat("Speed", 1);
                }
                if (pmp.Dir.Has(PlayerMovePackage.Direction.Back))
                {
                    anim.SetFloat("Speed", -1);
                }

                if (pmp.Dir == PlayerMovePackage.Direction.Stop)
                {
                    setGangnamVisible(true);
                }
                else
                {
                    setGangnamVisible(false);
                }

                anim.speed = animSpeed;

                //float h = Input.GetAxis("Horizontal");				// setup h variable as our horizontal input axis
                //float v = Input.GetAxis("Vertical");				// setup v variables as our vertical input axis
                //print(h + " | " + v);
                //anim.SetFloat("Speed", v);							// set our animator's float parameter 'Speed' equal to the vertical input axis
                //anim.SetFloat("Direction", h);                        // set our animator's float parameter 'Direction' equal to the horizontal input axis
                //anim.speed = animSpeed;								// set the speed of our animator to the public variable 'animSpeed'
                //anim.SetLookAtWeight(lookWeight);					// set the Look At Weight - amount to use look at IK vs using the head's animation	}
            }
            else if (!IsControlled)
            {
                //set rotation
                float newRotX = pmp.Rotation.x - transform.root.rotation.eulerAngles.x;
                float newRotY = pmp.Rotation.y - transform.root.rotation.eulerAngles.y;
                float newRotZ = pmp.Rotation.z - transform.root.rotation.eulerAngles.z;
                transform.root.Rotate(newRotX, newRotY, newRotZ);
            }
        }
        else if (dp is FlagPackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            FlagPackage fp = (FlagPackage)dp;
            if (fp.Event == FlagPackage.FlagEvent.Capture)
            {
                Score += 3;
            }
            else if (fp.Event == FlagPackage.FlagEvent.Drop)
            {
                Score--;
            }
        }
        else if (dp is FireWeaponPackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            FireWeaponPackage fwp = (FireWeaponPackage)dp;

            //Set laser target
            Camera c       = GetComponentInChildren <Camera>();
            float  newRotX = fwp.Target - c.transform.rotation.eulerAngles.x;
            c.transform.Rotate(newRotX, 0, 0);

            startFiringPackageSent = false;
            stopFiringPackageSent  = false;
            firing    = fwp.Enabled;
            fireTimer = 0;
        }
        else if (dp is PlayerHealthPackage)
        {
            PlayerHealthPackage php = (PlayerHealthPackage)dp;
            if (!php.PlayerIP.Equals(PlayerIP))
            {
                return;
            }

            Health -= php.Value;

            if (IsDead)
            {
                Health = 0;
                Die();
            }
        }
        else if (dp is PlayerSpawnPackage && dp.SenderRemoteIPEndpoint.Address.Equals(PlayerIP))
        {
            setRobotVisible(true);
            setGangnamVisible(true);

            Health = 100;

            if (IsControlled)
            {
                GameManager.Instance.spawnRobot(PlayerIP);
            }
        }
    }
Ejemplo n.º 5
0
    void HandleFiring()
    {
        // If you press the fire key, or when you are still firing
        if ((!firing && Input.GetKeyDown(Options.Controls.Fire)) || (firing && fireTimer >= 20))
        {
            if(!startFiringPackageSent)
            {
                startFiringPackageSent = true;

                FireWeaponPackage fwp = new FireWeaponPackage();
                fwp.Enabled = true;
                fwp.Target = GetComponentInChildren<Camera>().transform.rotation.eulerAngles.x;
                NetworkManager.Instance.Client.SendData(fwp);

                Fire();
            }
        }
        else if(firing && !Input.GetKey(Options.Controls.Fire))
        {
            if (!stopFiringPackageSent)
            {
                stopFiringPackageSent = true;
                FireWeaponPackage fwp = new FireWeaponPackage();
                fwp.Enabled = false;
                fwp.Target = GetComponentInChildren<Camera>().transform.rotation.eulerAngles.x;
                NetworkManager.Instance.Client.SendData(fwp);
            }
        }
    }