Ejemplo n.º 1
0
    /*
     *  ProcessUserCmd
     *  Parameters:
     *  1) UserCmd cmd
     *      This is the usercmd that we're going to process, this code should only be called on the server instance of the object
     *  TODO(Jake): Allow the local player to process their own usercmd upon creation AKA Client-Sided Prediction
     *  https://en.wikipedia.org/wiki/Client-side_prediction
     */
    public PlayerState ProcessUserCmd(UserCmd cmd, PlayerState playerState, float dt)
    {
        if (isServer)
        {
            // Check if we're trying to fire.
            if (cmd.ActionWasReleased(PlayerInputSynchronization.IN_FIRE, Input.LastUserCommand))
            {
                GameObject projectile = Instantiate(
                    m_ProjectilePrefab,
                    m_TargetController.transform.position + m_ProjectileOffset,
                    m_ProjectilePrefab.transform.rotation);

                NetworkServer.Spawn(projectile);
                audiosource.PlayOneShot(sound_shoot, 0.3f);
            }
            else
            {
                //Debug.Log("NOt fired");
            }
        }

        if (m_TargetController)
        {
            return(m_TargetController.StateUpdate(cmd, playerState, dt)); //Move our ship
        }

        return(null);
    }