Advertisement
Guest User

Untitled

a guest
Jun 20th, 2014
214
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 System.Collections;
  3.  
  4. public class WeaponSystem : MonoBehaviour {
  5. public int TheDamage1;
  6. public int TheDamage2;
  7.  
  8. public float Distance;
  9. public float MaxDistance;
  10. public Animator TheAnimator;
  11.  
  12. public float DammageDelay;
  13.  
  14. public int Hit01Streak;
  15. public int Hit02Streak;
  16.  
  17. public AudioClip[] HitWood;
  18. public AudioClip[] HitConcrete;
  19. public AudioClip[] HitMetal;
  20. public AudioClip[] HitGlass;
  21. public AudioClip[] HitEnemy;
  22. public AudioClip[] HitDirt;
  23. public AudioClip[] Swing;
  24.  
  25. public GameObject woodFX;
  26. public GameObject concreteFX;
  27. public GameObject glassFX;
  28. public GameObject metalFX;
  29. public GameObject bloodFX;
  30. public GameObject dirtFX;
  31.  
  32. public GameObject decal;
  33. public GameObject decalGlass;
  34.  
  35. public float addpos;
  36.  
  37. public bool canhit;
  38. public float attackTimer;
  39. public float coolDown;
  40.  
  41. public float Durability;
  42. public float MaxDurability;
  43. public float MinusDur1;
  44. public float MinusDur2;
  45. public bool havewalk;
  46. static public bool canharvestwood;
  47. public bool canharvestwood2;
  48. static public bool canharveststone;
  49. public bool canharveststone2;
  50. public GameObject wood;
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57. // Update is called once per frame
  58. void Update () {
  59. canharvestwood = canharvestwood2;
  60. canharveststone = canharveststone2;
  61.  
  62. if (Durability >= MaxDurability) {
  63. Durability = MaxDurability;
  64.  
  65. }
  66.  
  67. if (Durability <= 0) {
  68. Durability = 0;
  69.  
  70. }
  71. if (Durability <= 0) {
  72. Destroy (gameObject);
  73.  
  74. }
  75.  
  76. if (attackTimer > 0)
  77. attackTimer -= Time.deltaTime;
  78.  
  79. if (attackTimer < 0)
  80. attackTimer = 0;
  81. if (Input.GetButtonDown ("Fire1")) {
  82. if (attackTimer == 0) {
  83. AttackDammage ();
  84. AttackSound ();
  85. print ("Hit");
  86.  
  87. attackTimer = coolDown;
  88. }
  89.  
  90. }
  91. }
  92. void AttackSound () {
  93. audio.clip = (Swing[Random.Range(0,Swing.Length)]);
  94. audio.Play();
  95. }
  96.  
  97. IEnumerator AttackDammage() {
  98. if(Random.value >= 0.5 && Hit01Streak <=2)
  99. {
  100. TheAnimator.SetBool("Hit01", true);
  101. Hit01Streak += 1;
  102. Hit02Streak = 0;
  103.  
  104.  
  105.  
  106. }
  107. else
  108. {
  109. if (Hit02Streak <= 2)
  110. {
  111.  
  112. TheAnimator.SetBool("Hit02",true);
  113. Hit01Streak = 0;
  114. Hit02Streak += 1;
  115.  
  116.  
  117.  
  118. }
  119. else
  120. {
  121. TheAnimator.SetBool("Hit01", true);
  122. Hit01Streak +=1;
  123. Hit02Streak = 0;
  124.  
  125.  
  126. }
  127. }
  128. yield return new WaitForSeconds(DammageDelay);
  129.  
  130. //actual attack
  131. RaycastHit hit;
  132. var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
  133. if(Physics.Raycast(ray, out hit))
  134. {
  135. Distance = hit.distance;
  136. if(Distance < MaxDistance)
  137. {
  138. //var hitRotation = Quaternion.Euler( Random.Range(0, 360) , 0 , 0); //not working
  139. Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
  140.  
  141.  
  142.  
  143. if(hit.transform.gameObject.tag == "Wood") {
  144. Instantiate(woodFX, hit.point, hitRotation);
  145. audio.clip = (HitWood[Random.Range(0,HitWood.Length)]);
  146. audio.Play();
  147. Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
  148.  
  149.  
  150. }
  151. if(hit.transform.gameObject.tag == "Concrete") {
  152. Instantiate(concreteFX, hit.point, hitRotation);
  153. audio.clip = (HitConcrete[Random.Range(0,HitConcrete.Length)]);
  154. audio.Play();
  155. Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
  156.  
  157. }
  158. if(hit.transform.gameObject.tag == "Glass") {
  159.  
  160. Instantiate(glassFX, hit.point, hitRotation);
  161. audio.clip = (HitGlass[Random.Range(0,HitGlass.Length)]);
  162. audio.Play();
  163. Instantiate(decalGlass, hit.point + (hit.normal * addpos), hitRotation);
  164.  
  165. }
  166. if(hit.transform.gameObject.tag == "Dirt") {
  167. Instantiate(dirtFX, hit.point + (hit.normal * addpos), hitRotation);
  168.  
  169. Instantiate(dirtFX, hit.point, hitRotation);
  170. audio.clip = (HitDirt[Random.Range(0,HitDirt.Length)]);
  171. audio.Play();
  172. Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
  173.  
  174. }
  175. if(hit.transform.gameObject.tag == "Metal") {
  176. Instantiate(metalFX, hit.point, hitRotation);
  177. audio.clip = (HitMetal[Random.Range(0,HitMetal.Length)]);
  178. audio.Play();
  179. Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
  180.  
  181. }
  182. if(hit.transform.gameObject.tag == "Enemy") {
  183. Instantiate(bloodFX, hit.point, hitRotation);
  184. audio.clip = (HitEnemy[Random.Range(0,HitEnemy.Length)]);
  185. audio.Play();
  186. Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
  187.  
  188. }
  189.  
  190.  
  191. hit.transform.SendMessage("ApplyTheDammage", Random.Range(TheDamage1,TheDamage2) , SendMessageOptions.DontRequireReceiver);
  192. // var blood = Instantiate(bloodFX, transform.position, Quaternion.identity);
  193.  
  194. Durability -= Random.Range(MinusDur1,MinusDur2);
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201. }
  202. }
  203. TheAnimator.SetBool("Hit01", false);
  204. TheAnimator.SetBool("Hit02", false);
  205.  
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement