Advertisement
Guest User

Untitled

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