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

Namespace: Sfs2X.Requests
Assembly: SmartFox2X (in SmartFox2X.dll) Version: 1.7.3.0 (1.7.3)

Syntax

C#
public class SpectatorToPlayerRequest : BaseRequest

Remarks

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

Examples

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

Inheritance Hierarchy

System..::..Object
  BaseRequest
    Sfs2X.Requests..::..SpectatorToPlayerRequest

See Also