Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Diagnostics;
- using UnityEngine.Networking;
- public class PlayerController : NetworkBehaviour {
- [SyncVar]
- public float input = 0;
- [SyncVar]
- public float speed = 0.5f;
- Stopwatch stunTimer;
- Animator animator;
- Rigidbody rigidbody;
- public int maxStunTime;
- [SyncVar]
- private Color normalColor;
- private FactionManager manager;
- [SyncVar]
- public bool stunned;
- // Use this for initialization
- void Start() {
- animator = GetComponent<Animator>();
- rigidbody = GetComponent<Rigidbody>();
- stunTimer = new Stopwatch();
- manager = GetComponent<FactionManager>();
- }
- void FixedUpdate() {
- if (!stunTimer.IsRunning) {
- GetComponent<NetworkAnimator>().SetParameterAutoSend(0, true);
- if (isLocalPlayer) {
- float newSpeed = speed;
- rigidbody.AddRelativeForce(new Vector3(Input.GetAxisRaw("Horizontal") * newSpeed, 0, input = Input.GetAxisRaw("Vertical") * newSpeed), ForceMode.VelocityChange);
- animator.SetFloat("MovementX", Input.GetAxisRaw("Horizontal"));
- animator.SetFloat("MovementY", Input.GetAxisRaw("Vertical"));
- }
- } else {
- if (stunTimer.ElapsedMilliseconds >= maxStunTime) {
- stunTimer.Stop();
- stunTimer.Reset();
- manager.InitiateColorChange(normalColor);
- stunned = false;
- }
- }
- }
- // Update is called once per frame
- void Update() {
- }
- [Command]
- public void CmdStun() {
- // Report that the stun was sent
- UnityEngine.Debug.Log("Stun Sent");
- RpcStun();
- }
- [ClientRpc]
- public void RpcStun() {
- // Activate the stun.
- stunTimer.Start();
- // Track the players original color.
- normalColor = manager.color;
- // Make the players bot look like its shut down.
- manager.InitiateColorChange(Color.black);
- // Other code will check against this before trying to send another stun command.
- stunned = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement