Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Networking;
  3.  
  4. public class Energy : NetworkBehaviour {
  5.  
  6.     [SyncVar]
  7.     public int energy;
  8.     public bool InfiniteEnergy;
  9.    
  10.     [Command]
  11.     public void CmdSetEnergy( int newenergy ) {
  12.         if( InfiniteEnergy ) {
  13.             newenergy = 100;
  14.         }
  15.         RpcSetEnergy( newenergy );
  16.         SetEnergy( newenergy );
  17.     }
  18.  
  19.     [ClientRpc]
  20.     public void RpcSetEnergy( int newenergy ) {
  21.         SetEnergy( newenergy );
  22.     }
  23.  
  24.     public void SetEnergy( int newenergy ) {
  25.         if( InfiniteEnergy ) {
  26.             newenergy = 100;
  27.         }
  28.         energy = newenergy;
  29.         if( energy > 100 ) {
  30.             energy = 100;
  31.             return;
  32.         }      
  33.         if( energy <= 0 ) {
  34.             energy = 0;
  35.         }
  36.     }
  37.  
  38.    
  39.     public void SetInfiniteEnergy( bool state ) {
  40.         CmdSetInfiniteEnergy( state );
  41.     }
  42.  
  43.     [Command]
  44.     public void CmdSetInfiniteEnergy( bool state ) {
  45.         InfiniteEnergy = state;
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement