Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Networking;
- public class HealthPack : NetworkBehaviour {
- [SyncVar(hook = "OnVisibleChanged")]
- bool visible;
- public override void OnStartServer ()
- {
- visible = true;
- }
- public override void OnStartClient ()
- {
- OnVisibleChanged(visible);
- }
- [ServerCallback]
- void OnTriggerEnter(Collider other)
- {
- StartCoroutine(handlePickup());
- other.GetComponent<HealthAndDamage>().health += 10;
- }
- [Server]
- IEnumerator handlePickup()
- {
- visible = false;
- yield return new WaitForSeconds(15);
- visible = true;
- }
- void OnVisibleChanged(bool newValue)
- {
- GetComponent<Renderer>().enabled = newValue;
- GetComponent<Collider>().enabled = newValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment