Advertisement
Boomsma95

Tutorial Script: Playermanager

Mar 26th, 2013
1,955
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerManager : MonoBehaviour
  5. {
  6.     public MPPlayer thisplayer
  7.     {
  8.         get
  9.         {
  10.             return MultiplayerManager.GetMPPlayer(networkView.owner);
  11.         }
  12.     }
  13.     public PlayerController Controller;
  14.     public Transform ControllerTransform;
  15.  
  16.     public GameObject OutsideView;
  17.  
  18.     public Vector3 CurrentPosition;
  19.     public Quaternion CurrentRotation;
  20.  
  21.     void Start()
  22.     {
  23.         DontDestroyOnLoad(gameObject);
  24.         ControllerTransform.gameObject.SetActive(false);
  25.         OutsideView.SetActive(false);
  26.         //thisplayer = MultiplayerManager.GetMPPlayer(networkView.owner); //FIX TUTORIAL #7 - Remove This Part and add the part above.
  27.         thisplayer.PlayerManager = this;
  28.     }
  29.  
  30.     void FixedUpdate()
  31.     {
  32.         if (networkView.isMine)
  33.         {
  34.             CurrentPosition = ControllerTransform.position;
  35.             CurrentRotation = ControllerTransform.rotation;
  36.         }
  37.         else
  38.         {
  39.             //ControllerTransform.position = CurrentPosition; //FIX TUTORIAL #7 - Remove this part and add the part below.
  40.             OutsideView.transform.position = CurrentPosition + new Vector3(0,-1f,0);
  41.             OutsideView.transform.rotation = CurrentRotation;
  42.         }
  43.     }
  44.  
  45.     void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
  46.     {
  47.         if (stream.isWriting)
  48.         {
  49.             stream.Serialize(ref CurrentPosition);
  50.             stream.Serialize(ref CurrentRotation);
  51.         }
  52.         else
  53.         {
  54.             stream.Serialize(ref CurrentPosition);
  55.             stream.Serialize(ref CurrentRotation);
  56.         }  
  57.     }
  58.  
  59.     void GetBulletDamage(int damage)
  60.     {
  61.         if (Network.isServer)
  62.             Server_HandleBulletDamage(damage);
  63.         else
  64.             networkView.RPC("Server_HandleBulletDamage", RPCMode.Server, damage);
  65.     }
  66.  
  67.     [RPC]
  68.     public void Server_HandleBulletDamage(int damage)
  69.     {
  70.         thisplayer.PlayerHealth -= damage;
  71.         if (thisplayer.PlayerHealth <= 0) //WHEN DEAD
  72.         {
  73.             thisplayer.PlayerIsAlive = false;
  74.             thisplayer.PlayerHealth = 0;
  75.             networkView.RPC("Client_PlayerDead", RPCMode.All);
  76.             MultiplayerManager.instance.networkView.RPC("Client_UpdatePlayerHealthAndAlive", RPCMode.Others,thisplayer.PlayerNetwork, false, 0);
  77.         }
  78.         else // WHEN ALIVE GETTITNG HIT
  79.         {
  80.             MultiplayerManager.instance.networkView.RPC("Client_UpdatePlayerHealthAndAlive", RPCMode.All, thisplayer.PlayerNetwork, thisplayer.PlayerIsAlive, thisplayer.PlayerHealth);
  81.         }
  82.     }
  83.  
  84.     [RPC]
  85.     public void Client_PlayerDead()
  86.     {
  87.         OutsideView.SetActive(false);
  88.         if (networkView.isMine)
  89.             ControllerTransform.gameObject.SetActive(false);
  90.     }
  91.  
  92.     [RPC]
  93.     public void Client_PlayerAlive()
  94.     {
  95.         if (networkView.isMine)
  96.             ControllerTransform.gameObject.SetActive(true);
  97.         else
  98.             OutsideView.SetActive(true);
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement