Volleyball Rotation System

Hey guys

I’m through quite a few tutorials (Udemy.com, highly recommended!) by beginning to learn C# and trying to wrap my head around a way to create a system to recreate the rotation system in volleyball for my game. This is what I have gotten through so far…

  • Created enumerators for all of the different states that can occur in the volleyball match (e.g. serve, set, pass, attack, block, defence)
  • Created classes for the players information (name, current position, various other statistics)
  • Created arrays for what position every player will be in in various situations (e.g. in the serve state in rotation 1, player 2 starts in x position and moves from a to b)

What I am stuck with is how to link both the classes of the players and the arrays for what position every player will be in. In solving this, I can also achieve the assigning of statistics to the actions. For example, if the set goes to position 4 to attack I want to be able to just assign a spike attempt (and whatever the result would be) to whoever is currently in position 4 at that time, not specifically have to reference the player by their class.

I have attached a picture below giving a rough idea of what I am trying to achieve and also a screenshot of what Ive gotten through so far with my UI. Any help is appreciated!


Perhaps create a static list of the player classes? The list length is the number of positions in the court, and each list item is a reference to the player that is in the corresponding position. Of course, it would be up to your scripting to manage the list to make sure it’s always updated, but if you can do this, then you can, at any time, reference positionList[4] (or whatever) and it will contain the reference to the player in that position.

I wouldn’t recommenced a static list of player classes but perhaps having a player manager object that either creates the player objects at the start of the scene or all player objects register to.

Thanks for your reply! Im gonna have a bit of a play around and see what I can whip up!

Is there some tutorials or information around than I can find on creating an object such as what you suggested? And then to also assign the created players to that manger object and the reference them elsewhere in the scripts?

I need to correct myself: Not a static list of classes, a static list of the player objects. In other words, a list of objects that are OF the player class.

Why not use this? It can be used as a full-scope list that can be referenced from any script without the need for creating a manager object.

That would make sense Hyblademin. I just prefer having an overseeing manager for things like this.

and for the approach i would do something like this.

public class PlayerManager : MonoBehaviour {
  
    public playerPrefab;
  
    Player[] players;
  
    void Start () {
        players = new Player[4];
      
        for (int i = 0; i < players.Length; i++) {
          
            GameObject go = (GameObject)Instantiate (playerPrefab);
            players[i] = go.GetComponent<Player> ();
            players[i].manager = this;
        }
    }
}

Thanks for the example! Is it then easy assign the instantiated GameObject to variable of a player class so that I can access the other information about the players for statistics?

Im unsure what you mean. If you mean access the other player objects from within a player class just use the reference to the manager. Just make the players array public.

Thats exactly what I meant! Just being able to access the player information for assigning statistics is important for the game

Just trying punch this code in but getting an error on the playerPrefab line, do I have to put GameObject in between public and playerPrefab? Also add the namespace at the top of the script for using lists?

Not looking for you to write my code for me, the direction you’ve provided for this beginner has already been awesome!

Yeah you do, sorry, it was really late at night when I wrote that.

Player[] players;

This section is giving me an error? Is there I should be adding because at the moment the name “Player” doesn’t exist in the current context?

“Player” should be replaced by your player class