Advertisement
Guest User

Melee System

a guest
Aug 27th, 2014
175
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.  
  7. function Update ()
  8. {
  9.     if (Input.GetButtonDown("Fire1"))
  10.     {
  11.         var hit : RaycastHit;
  12.         if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit))
  13.         {
  14.             Distance = hit.distance;
  15.             if (Distance < MaxDistance)
  16.             {
  17.                 hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
  18.             }
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement