Advertisement
Guest User

Melee System

a guest
Aug 28th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3.  var TheDammage : int = 50;
  4.  var Distance : float;
  5.  var MaxDistance : float = 1.5;
  6.  var TheSystem : Transform;
  7.  
  8.  function Update ()
  9.  {
  10.     if (Input.GetButtonDown("Fire1"))
  11.     {
  12.     //Attack animation
  13.     animation.Play("Attack");
  14.     }
  15.     if (TheMace.animation.isPlaying == false)
  16.     {
  17.         TheMace.animation.CrossFade("Idle");
  18.     }
  19.     if (Input.GetKey (KeyCode.LeftShift))
  20.     {
  21.         TheMace.animation.CrossFade("Sprint");
  22.     }
  23.     if (Input.GetKeyUp(KeyCode.LeftShift))
  24.     {
  25.         TheMace.animation.CrossFade("Idle");
  26.     }
  27.  }
  28.  function AttackDammage ()
  29.  {
  30.  //You call this function in the animation event
  31.     var hit : RaycastHit;
  32.     if (Physics.Raycast (TheSystem.transform.position, TheSystem.transform.TransformDirection(Vector3.forward), hit))
  33.     {
  34.         Distance = hit.distance;
  35.         if (Distance < MaxDistance)
  36.         {
  37.             hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
  38.         }
  39.     }
  40.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement