How can I do a role system like among us'?

I’m making a game of tag so I’m looking for how to make one of the player (randomly) be who will tag someone and who will run. Use C#. Please say the code, I am using photon pun 2

we are people not AIs ask microsoft copilot that exact same prompt and you will get the answer:

Generated by microsoft copilot:

Certainly! To randomly assign roles to players in your game of tag using Photon PUN 2, you can follow these steps:

  1. Assign Player Numbers:
  • In your game, each player needs a unique identifier. You can use Photon’s built-in PlayerNumbering script to assign a player number to each player. This script automatically assigns numbers based on the order players join the room.
  • Make sure you have the PlayerNumbering script in your project (it’s part of the Photon PUN 2 package).
  • Use Player.ActorNumber to get the assigned player number for each player.
  1. Randomly Assign Roles:
  • When the game starts (e.g., in the OnJoinedRoom callback), the Master Client can randomly assign roles (e.g., tagger or runner) to each player.
  • You can use Random.Range to generate a random number (e.g., 0 or 1) to determine the role.
  • Send this role information to all players using Photon’s RaiseEvent method.
  1. Example Code:


using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

public class TagGameController : MonoBehaviourPunCallbacks
    private const int TaggerRole = 0;
    private const int RunnerRole = 1;

    public override void OnJoinedRoom()

        // Check if we are the Master Client
        if (PhotonNetwork.IsMasterClient)
            // Get the list of players in the room
            foreach (var player in PhotonNetwork.PlayerList)
                // Generate a random role (tagger or runner)
                int randomRole = Random.Range(0, 2);

                // Assign the role to the player
                player.SetCustomProperties(new Hashtable { { "Role", randomRole } });

                // Log the role for debugging
                Debug.Log($"Player {player.ActorNumber} is {(randomRole == TaggerRole ? "Tagger" : "Runner")}");

AI-generated code. Review and use carefully. More info on FAQ.

  • In this example, we use custom properties to store the player’s role (0 for tagger, 1 for runner).
  • Adjust the role assignment logic according to your game’s requirements.

Remember to adapt this code to your specific game mechanics and integrate it with your existing Photon PUN 2 setup. Good luck with your game of tag! :man_running::running_woman::label:

It’s because I am a new programmer. I started programing 8 months ago. But thanks!