Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Diagnostics;
  4. using UnityEngine.Networking;
  5.  
  6. public class PlayerController : NetworkBehaviour {
  7.     [SyncVar]
  8.     public float input = 0;
  9.     [SyncVar]
  10.     public float speed = 0.5f;
  11.     Stopwatch stunTimer;
  12.     Animator animator;
  13.     Rigidbody rigidbody;
  14.     public int maxStunTime;
  15.     [SyncVar]
  16.     private Color normalColor;
  17.     private FactionManager manager;
  18.     [SyncVar]
  19.     public bool stunned;
  20.  
  21.     // Use this for initialization
  22.     void Start() {
  23.         animator = GetComponent<Animator>();
  24.         rigidbody = GetComponent<Rigidbody>();
  25.         stunTimer = new Stopwatch();
  26.         manager = GetComponent<FactionManager>();
  27.     }
  28.  
  29.     void FixedUpdate() {
  30.         if (!stunTimer.IsRunning) {
  31.             GetComponent<NetworkAnimator>().SetParameterAutoSend(0, true);
  32.             if (isLocalPlayer) {
  33.                 float newSpeed = speed;
  34.                 rigidbody.AddRelativeForce(new Vector3(Input.GetAxisRaw("Horizontal") * newSpeed, 0, input = Input.GetAxisRaw("Vertical") * newSpeed), ForceMode.VelocityChange);
  35.                 animator.SetFloat("MovementX", Input.GetAxisRaw("Horizontal"));
  36.                 animator.SetFloat("MovementY", Input.GetAxisRaw("Vertical"));
  37.             }
  38.         } else {
  39.             if (stunTimer.ElapsedMilliseconds >= maxStunTime) {
  40.                 stunTimer.Stop();
  41.                 stunTimer.Reset();
  42.                 manager.InitiateColorChange(normalColor);
  43.                 stunned = false;
  44.             }
  45.         }
  46.     }
  47.  
  48.     // Update is called once per frame
  49.     void Update() {
  50.  
  51.     }
  52.  
  53.     [Command]
  54.     public void CmdStun() {
  55.         // Report that the stun was sent
  56.         UnityEngine.Debug.Log("Stun Sent");
  57.         RpcStun();
  58.     }
  59.  
  60.     [ClientRpc]
  61.     public void RpcStun() {
  62.         // Activate the stun.
  63.         stunTimer.Start();
  64.         // Track the players original color.
  65.         normalColor = manager.color;
  66.         // Make the players bot look like its shut down.
  67.         manager.InitiateColorChange(Color.black);
  68.         // Other code will check against this before trying to send another stun command.
  69.         stunned = true;
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement