Working with other network players gameobjects

Options
I have a situtation where i have 2 different type of gameobjects Player & Vehicle. Both are network instantiated to the game.

Player has the information about its vehicles starting position which is int in range from 0 - 3.
Depending on the starting position it affects the transform position of the vehicle.

The problem that i am trying to figure how do i set the vehicles colors depending on the start position integer.
The player holds the integer variable and the vehicle does not. Lets say i call a function inside my networkvehicle script such as

public void SetVehicleColors()
{

GameObject[] vehicles;
vehicles = GameObject.FindGameObjectsWithTag("Vehicle");
Vehicle vehicle;
int length = vehicles.Length;

for (int i = 0; i < length; i++)
{
vehicle = vehicles[i].GetComponent();
vehicle.SetVehicleColor(vehicleManager.Player.GameManager.ColorManager, i);
}

}

The i in there is the color index of the vehicle. But instead of iterating the color from 0 -> length i want to use the vehicles owner the players start position as the color index.

I am thinking i could keep up with another integer inside the networkvehicle script that is identical to the players starting point value but isn't this kinda redundant since then i would have same variable with same values in two different scripts.

Is it expensive networkwise to keep track of other players scripts?

Thanks in advance. Darrel

Answers

  • Darrelfin
    Options
    So i figured how to do this.

    I store the vehicle start position in custom property in networkvehicle class. The colors are stored in the same class as the networkvehicle as array of colors.
    When game starts i just call SetColorsRPC function

    public void SetColorsRPC()
    {
    photonView.RPC("SetColors", PhotonTargets.AllViaServer, m_vehicleProperties["sp"]);
    }
    [PunRPC]
    public void SetColors(int index)
    {
    gameObject.GetComponent().SetVehicleColor(PriVehicleColor, SecVehicleColor, index);
    }