Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Melee_Attack : MonoBehaviour {
  6.  
  7. public Transform Enemy;
  8.  
  9. //public Transform meleepoint;
  10. public float range;
  11.  
  12. // Use this for initialization
  13. void Start () {
  14.  
  15.  
  16. }
  17.  
  18. // Update is called once per frame
  19. void Update () {
  20. if (Input.GetKeyDown(KeyCode.E)) {
  21. MeleeAttack();
  22. }
  23. }
  24.  
  25. void MeleeAttack() {
  26. Transform MyEnemy = Enemy;
  27. RaycastHit2D hit = Physics2D.Raycast(transform.position,transform.forward, range);
  28. if (hit.rigidbody != null) {
  29. Debug.Log(hit.collider.name);
  30. if (hit.rigidbody == MyEnemy.GetComponent<Rigidbody>()) {
  31. Debug.Log("Enemy Found");
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement