GetRole
IM Class - GetRole
Method
Overview
The GetRole
method in the IM class is utilized for obtaining a specific role within the game using its name or ID.
Syntax
public static Role GetRole(string roleNameOrId)
Description
This method searches for a role by its name or unique ID within the game's active role list. If a matching role is found, it returns the corresponding Role
object.
Example of Usage
public class RoleInfoDisplay : MonoBehaviour {
void DisplayRoleInfo() {
// Retrieve a role by name or ID
var role = IM.GetRole("Leader");
// Check if the role exists and display information
if (role != null) {
Debug.Log($"Role Name: {role.RoleName}");
Debug.Log($"Role Description: {role.Description}");
} else {
Debug.Log("Role not found.");
}
}
}
Remarks
- This method is essential for dynamically accessing and utilizing role information in various game scenarios, such as assigning roles to actors or displaying role-specific details.
- Accurate retrieval requires the provided role name or ID to match precisely with the ones in the game's role list.