Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Networking;
- public class Energy : NetworkBehaviour {
- [SyncVar]
- public int energy;
- public bool InfiniteEnergy;
- [Command]
- public void CmdSetEnergy( int newenergy ) {
- if( InfiniteEnergy ) {
- newenergy = 100;
- }
- RpcSetEnergy( newenergy );
- SetEnergy( newenergy );
- }
- [ClientRpc]
- public void RpcSetEnergy( int newenergy ) {
- SetEnergy( newenergy );
- }
- public void SetEnergy( int newenergy ) {
- if( InfiniteEnergy ) {
- newenergy = 100;
- }
- energy = newenergy;
- if( energy > 100 ) {
- energy = 100;
- return;
- }
- if( energy <= 0 ) {
- energy = 0;
- }
- }
- public void SetInfiniteEnergy( bool state ) {
- CmdSetInfiniteEnergy( state );
- }
- [Command]
- public void CmdSetInfiniteEnergy( bool state ) {
- InfiniteEnergy = state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement