Search Unity

Question Netcode Cinemachine for Different Character Classes

Discussion in 'Multiplayer' started by Osilidath, Jun 10, 2023.

  1. Osilidath


    Jun 29, 2022
    I'm working on a project with 3 different character classes. And every class have a different POV, so different Cinemachine GameObjects. I have for example A, B and C character classes. Each player can select same or different character classes. For example class selection can be AAA, BBB, CCC, AAB, AAC, ABC etc. I have total 10 combinations if I'm not wrong. I define priorities in If(IsOwner) class in OnNetworkSpawn function. Code is given below.

    Code (CSharp):
    1.  [SerializeField] private CinemachineVirtualCamera vc;
    3. public override void OnNetworkSpawn()
    4.     {
    5.         if(IsOwner)
    6.         {
    7.             listener.enabled = true;
    8.             vc.Priority = 1;
    9.         }
    10.         else
    11.         {
    12.             vc.Priority = 0;
    13.         }
    14.     }
    If players select the same classes (AAA, BBB, CCC), everthing works as it should be. But if players select different classes, (AAB, AAC, ABC etc.) this code doesn't work. Code is in a single C# script where every class uses the same C# script. Should I use this code in each character classes own scripts? Also I was thinking switch-case would help me solve my problem but I'm not really sure how can I use it on this spesific occasion. Any help is appreciated. Thanks.