Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.99 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Networking;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5.  
  6. public class PlayerController : NetworkBehaviour
  7. {
  8. static Animator anim;
  9. public Animation ani;
  10.  
  11. [SyncVar]
  12. public int currentHealth = 100;
  13. [SyncVar]
  14. public float speed = -38.0f;
  15. [SyncVar]
  16. public int maxHealth = 100;
  17. [SyncVar]
  18. public int damage = 20;
  19. [SyncVar]
  20. public int maxStamina = 100;
  21. [SyncVar]
  22. public int currentStamina = 100;
  23. [SyncVar]
  24. public int attackXP = 0;
  25. [SyncVar]
  26. public int lifeXP = 0;
  27. [SyncVar]
  28. public int speedXP = 0;
  29. [SyncVar]
  30. public int braveryXP = 0;
  31. [SyncVar]
  32. public int attackXPRequirement = 25;
  33. [SyncVar]
  34. public int lifeXPRequirement = 25;
  35. [SyncVar]
  36. public int speedXPRequirement = 25;
  37. [SyncVar]
  38. public int braveryXPRequirement = 2000;
  39. [SyncVar]
  40. public int attackPrestige = 0;
  41. [SyncVar]
  42. public int lifePrestige = 0;
  43. [SyncVar]
  44. public int speedPrestige = 0;
  45. [SyncVar]
  46. public int braveryPrestige = 0;
  47. public int levelCapAttack = 20;
  48. public int levelCapLife = 20;
  49. public int levelCapSpeed = 20;
  50. public int levelCapBravery = 5;
  51. [SyncVar]
  52. public int attackLevel = 1;
  53. [SyncVar]
  54. public int lifeLevel = 1;
  55. [SyncVar]
  56. public int speedLevel = 1;
  57. [SyncVar]
  58. public int braveryLevel = 1;
  59. [SyncVar]
  60. public int numberOfPrestigesAcquired = 0;
  61. [SyncVar]
  62. public int totalPrestigeCap = 8;
  63. [SyncVar]
  64. public bool canHit = false;
  65. [SyncVar]
  66. public bool attacking = false;
  67. [SyncVar]
  68. public bool isDead = false;
  69. [SyncVar]
  70. public bool godMode = false;
  71. [SyncVar]
  72. public int damageMinimum = 5;
  73.  
  74. void Update()
  75. {
  76. this.GetComponentInChildren<TextMesh>().text = pname;
  77. if (!isLocalPlayer) return;
  78.  
  79. damageMinimum = damage / 4;
  80.  
  81. if (Input.GetButtonDown("Fire1"))
  82. {
  83. if (attacking == false && isDead == false)
  84. {
  85. ani.Play("bibi_attack"); //this part currently creates errors
  86. anim.SetBool("IsAttacking", true);
  87. attacking = true;
  88. canHit = true;
  89. }
  90. }
  91.  
  92. if (!Input.GetButtonDown("Fire1"))
  93. {
  94. {
  95. anim.SetBool("IsAttacking", false);
  96. if (ani.IsPlaying("bibi_attack"))
  97. {
  98. attacking = false;
  99. }
  100. }
  101. }
  102.  
  103. if (currentHealth < maxHealth / 5)
  104. {
  105. anim.SetBool("InDanger", true);
  106. }
  107. else
  108. {
  109. anim.SetBool("InDanger", false);
  110. }
  111.  
  112.  
  113. if (attacking == false && isDead == false)
  114. {
  115. var x = Input.GetAxis("Horizontal") * Time.deltaTime * 450.0f;
  116. var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
  117.  
  118. transform.Rotate(0, x, 0);
  119. transform.Translate(0, 0, z);
  120.  
  121. if (z < 0)
  122. {
  123. anim.SetBool("IsWalking", true);
  124. }
  125. else
  126. {
  127. anim.SetBool("IsWalking", false);
  128. }
  129. }
  130.  
  131. if (attacking == true)
  132. {
  133. anim.SetBool("IsWalking", false);
  134. }
  135. else
  136. {
  137. anim.SetBool("IsAttacking", false);
  138. canHit = false;
  139. }
  140.  
  141. if (isLocalPlayer)
  142. {
  143. Camera.main.transform.position = this.transform.position - this.transform.forward * -10 + this.transform.up * 5;
  144. Camera.main.transform.LookAt(this.transform.position);
  145. }
  146. }
  147.  
  148. public override void OnStartLocalPlayer()
  149. {
  150. anim = GetComponent<Animator>();
  151. ani = GetComponent<Animation>();
  152. }
  153.  
  154. [SyncVar]
  155. public string pname = "";
  156. private void OnGUI()
  157. {
  158. if (isLocalPlayer)
  159. {
  160. pname = GUI.TextField(new Rect(25, Screen.height - 40, 100, 30), pname);
  161. if (GUI.Button(new Rect(130, Screen.height - 40, 180, 30), "Set as Serverside name"))
  162. {
  163. CmdChangeName(pname);
  164. }
  165. }
  166. }
  167.  
  168. [Command]
  169. public void CmdChangeName(string newName)
  170. {
  171. pname = newName;
  172. }
  173.  
  174. [Server]
  175. public void TakeDamage(int amount)
  176. {
  177. if (!isServer)
  178. {
  179. return;
  180. }
  181.  
  182. currentHealth -= amount;
  183. Debug.Log("Something was struck by a fist.");
  184. if (currentHealth <= 0)
  185. {
  186. currentHealth = 0;
  187. Debug.Log("Someone just died.");
  188. }
  189. }
  190.  
  191. private void OnTriggerEnter(Collider other)
  192. {
  193. if (canHit == true && !isLocalPlayer && godMode == false)
  194. {
  195. Debug.Log("My fist hit somebody. It works!");
  196. TakeDamage(Random.Range(damageMinimum, damage));
  197. canHit = false;
  198. }
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement