Search Unity

Instantiating a custom model

Discussion in 'Connected Games' started by reset, Aug 20, 2009.

  1. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Hi there

    if a wanted the players to choose the colours of their model before joining a networked game, how would I do this? Network.instantiate only offers position, rotation etc

    thanks
    Steve
     
  2. martinf35

    martinf35

    Joined:
    Jun 4, 2009
    Posts:
    6
    Hi
    I don't know if its the best one but do these steps in a script and it should work :

    1- Instantiate you prefab
    2- Color it as you want
    3- Create a NetworkView for this prefab
    4- Set your prefab that has been colors as the "observed" property of your networkview.
     
  3. reset

    reset

    Joined:
    May 22, 2009
    Posts:
    393
    Would it be:

    Where the script is attached to the prefab -

    function OnNetworkInstantiate (info : NetworkMessageInfo) {
    if (networkView.isMine)
    change model colour to colours chosen
    }

    Is this where I could do it?
     
  4. LukeB

    LukeB

    Joined:
    Aug 8, 2009
    Posts:
    88
    Best thing to use for this would be 'Resources.load();' as it can load a prefab from a string name.

    var chosen_pref="Blue Player";

    Network.Instantiate(Resources.Load(chosen_pref,GameObject),Transform,rotation..);

    For the above to work, a prefab called Blue Player would have to be in a folder called Resources in your project folder :)

    For the colour changing, you would do something more like this:
    Code (csharp):
    1.  
    2. var chosen_pref="Player";
    3.  
    4. var player=Network.Instantiate(Resources.Load(chosen_pref,GameObject),Transform,rotation..);
    5. player.renderer.material.color.r = 0;
    6. //this will change the red colour channel of 'player' to 0, making it go a bluey green colour on the local client (not across the network).