document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Networking;
  4.  
  5. public class HealthPack : NetworkBehaviour {
  6.     [SyncVar(hook = "OnVisibleChanged")]
  7.     bool visible;
  8.  
  9.     public override void OnStartServer ()
  10.     {
  11.         visible = true;
  12.     }
  13.  
  14.     public override void OnStartClient ()
  15.     {
  16.         OnVisibleChanged(visible);
  17.     }
  18.  
  19.     [ServerCallback]
  20.     void OnTriggerEnter(Collider other)
  21.     {
  22.         StartCoroutine(handlePickup());
  23.         other.GetComponent<HealthAndDamage>().health += 10;
  24.     }
  25.  
  26.     [Server]
  27.     IEnumerator handlePickup()
  28.     {
  29.         visible = false;
  30.         yield return new WaitForSeconds(15);
  31.         visible = true;
  32.     }
  33.        
  34.     void OnVisibleChanged(bool newValue)
  35.     {
  36.         GetComponent<Renderer>().enabled = newValue;
  37.         GetComponent<Collider>().enabled = newValue;
  38.     }
  39. }
');