Search Unity

Update the player that diamond is collected by making diamond missing from them

Discussion in 'Multiplayer' started by missy_pooh, Mar 17, 2012.

  1. missy_pooh

    missy_pooh

    Joined:
    Jun 1, 2011
    Posts:
    150
    Multiplayer
    So basically every player will see the same amount of diamond and same amount of enemy in the scene. So when player 1 collect one diamond, it will be missing from the other player. Hope it is clear. But from the code snippet below, it is not doing anything. Any ideas what wrong. As i will have many diamond in the scene, i have created an empty gameObject and gather all the diamonds into one game object. So for the network view, should i attached to the gameObject or for every diamond??

    Code (csharp):
    1.  
    2.  
    3. function OnTriggerEnter(hit : Collider)
    4. {
    5.         if(networkView.isMine){
    6.         if(hit.gameObject.tag == "diamond")
    7.         {
    8.             Destroy(hit.gameObject);
    9.             // play a sound clip at the exact position we hit the object
    10.             score = score + 1;
    11.             var exp = Instantiate(explosion, gameObject.transform.position , Quaternion.identity);
    12.             AudioSource.PlayClipAtPoint(hitSound, transform.position);
    13.         }
    14.     }
    15.   }
    16.  
    17.  
     
  2. missy_pooh

    missy_pooh

    Joined:
    Jun 1, 2011
    Posts:
    150
    bump. please help.:(
     
  3. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
  4. missy_pooh

    missy_pooh

    Joined:
    Jun 1, 2011
    Posts:
    150
  5. roto23

    roto23

    Joined:
    Oct 30, 2009
    Posts:
    240
    If I was writing this I would create a separate game object for each diamond. When a player picks one up, just destroy it and let Unity's State Synchronization handle the rest. I may be generalizing a bit in that this may turn out to be a RPC function you create and you would call it inside your trigger.
     
    Last edited: Mar 19, 2012