Turns the current user from player to spectator in a Game Room.

Namespace: Sfs2X.Requests
Assembly: SmartFox2X (in SmartFox2X.dll) Version: 1.7.0.0 (1.7.0)

Syntax

C#
public class PlayerToSpectatorRequest : BaseRequest

Remarks

If the operation is successful, all the users in the target Room are notified with the PLAYER_TO_SPECTATOR event. The operation could fail if no spectator slots are available in the Game Room at the time of the request; in this case the PLAYER_TO_SPECTATOR_ERROR event is dispatched to the requester's client.

Examples

The following example turns the current user from player to spectator in the last joined Game Room:
 Copy imageCopy
void SomeMethod() {
    sfs.AddEventListener(SFSEvent.PLAYER_TO_SPECTATOR, OnPlayerToSpectatorSwitch);
    sfs.AddEventListener(SFSEvent.PLAYER_TO_SPECTATOR_ERROR, OnPlayerToSpectatorSwitchError);
    // Switch player to spectator
    sfs.Send( new PlayerToSpectatorRequest() );
}
void OnPlayerToSpectatorSwitch(BaseEvent evt) {
    User user = (User)evt.Params["user"];
    Console.WriteLine("Player " + user.Name + " is now a spectator");                           // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Player " + user.Name + " is now a spectator");          // Windows Universal
}
void OnPlayerToSpectatorSwitchError(BaseEvent evt) {
    Console.WriteLine("Unable to become a spectator due to the following error: " + (string)evt.Params["errorMessage"]);                        // .Net / Unity
    System.Diagnostics.Debug.WriteLine("Unable to become a spectator due to the following error: " + (string)evt.Params["errorMessage"]);       // Windows Universal
}

Inheritance Hierarchy

System..::..Object
  BaseRequest
    Sfs2X.Requests..::..PlayerToSpectatorRequest

See Also