Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- using System.Collections;
- public class PlayerController : NetworkBehaviour
- {
- static Animator anim;
- public Animation ani;
- [SyncVar]
- public int currentHealth = 100;
- [SyncVar]
- public float speed = -38.0f;
- [SyncVar]
- public int maxHealth = 100;
- [SyncVar]
- public int damage = 20;
- [SyncVar]
- public int maxStamina = 100;
- [SyncVar]
- public int currentStamina = 100;
- [SyncVar]
- public int attackXP = 0;
- [SyncVar]
- public int lifeXP = 0;
- [SyncVar]
- public int speedXP = 0;
- [SyncVar]
- public int braveryXP = 0;
- [SyncVar]
- public int attackXPRequirement = 25;
- [SyncVar]
- public int lifeXPRequirement = 25;
- [SyncVar]
- public int speedXPRequirement = 25;
- [SyncVar]
- public int braveryXPRequirement = 2000;
- [SyncVar]
- public int attackPrestige = 0;
- [SyncVar]
- public int lifePrestige = 0;
- [SyncVar]
- public int speedPrestige = 0;
- [SyncVar]
- public int braveryPrestige = 0;
- public int levelCapAttack = 20;
- public int levelCapLife = 20;
- public int levelCapSpeed = 20;
- public int levelCapBravery = 5;
- [SyncVar]
- public int attackLevel = 1;
- [SyncVar]
- public int lifeLevel = 1;
- [SyncVar]
- public int speedLevel = 1;
- [SyncVar]
- public int braveryLevel = 1;
- [SyncVar]
- public int numberOfPrestigesAcquired = 0;
- [SyncVar]
- public int totalPrestigeCap = 8;
- [SyncVar]
- public bool canHit = false;
- [SyncVar]
- public bool attacking = false;
- [SyncVar]
- public bool isDead = false;
- [SyncVar]
- public bool godMode = false;
- [SyncVar]
- public int damageMinimum = 5;
- void Update()
- {
- this.GetComponentInChildren<TextMesh>().text = pname;
- if (!isLocalPlayer) return;
- damageMinimum = damage / 4;
- if (Input.GetButtonDown("Fire1"))
- {
- if (attacking == false && isDead == false)
- {
- ani.Play("bibi_attack"); //this part currently creates errors
- anim.SetBool("IsAttacking", true);
- attacking = true;
- canHit = true;
- }
- }
- if (!Input.GetButtonDown("Fire1"))
- {
- {
- anim.SetBool("IsAttacking", false);
- if (ani.IsPlaying("bibi_attack"))
- {
- attacking = false;
- }
- }
- }
- if (currentHealth < maxHealth / 5)
- {
- anim.SetBool("InDanger", true);
- }
- else
- {
- anim.SetBool("InDanger", false);
- }
- if (attacking == false && isDead == false)
- {
- var x = Input.GetAxis("Horizontal") * Time.deltaTime * 450.0f;
- var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
- transform.Rotate(0, x, 0);
- transform.Translate(0, 0, z);
- if (z < 0)
- {
- anim.SetBool("IsWalking", true);
- }
- else
- {
- anim.SetBool("IsWalking", false);
- }
- }
- if (attacking == true)
- {
- anim.SetBool("IsWalking", false);
- }
- else
- {
- anim.SetBool("IsAttacking", false);
- canHit = false;
- }
- if (isLocalPlayer)
- {
- Camera.main.transform.position = this.transform.position - this.transform.forward * -10 + this.transform.up * 5;
- Camera.main.transform.LookAt(this.transform.position);
- }
- }
- public override void OnStartLocalPlayer()
- {
- anim = GetComponent<Animator>();
- ani = GetComponent<Animation>();
- }
- [SyncVar]
- public string pname = "";
- private void OnGUI()
- {
- if (isLocalPlayer)
- {
- pname = GUI.TextField(new Rect(25, Screen.height - 40, 100, 30), pname);
- if (GUI.Button(new Rect(130, Screen.height - 40, 180, 30), "Set as Serverside name"))
- {
- CmdChangeName(pname);
- }
- }
- }
- [Command]
- public void CmdChangeName(string newName)
- {
- pname = newName;
- }
- [Server]
- public void TakeDamage(int amount)
- {
- if (!isServer)
- {
- return;
- }
- currentHealth -= amount;
- Debug.Log("Something was struck by a fist.");
- if (currentHealth <= 0)
- {
- currentHealth = 0;
- Debug.Log("Someone just died.");
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (canHit == true && !isLocalPlayer && godMode == false)
- {
- Debug.Log("My fist hit somebody. It works!");
- TakeDamage(Random.Range(damageMinimum, damage));
- canHit = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement