Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Melee_Attack : MonoBehaviour {
- public Transform Enemy;
- //public Transform meleepoint;
- public float range;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKeyDown(KeyCode.E)) {
- MeleeAttack();
- }
- }
- void MeleeAttack() {
- Transform MyEnemy = Enemy;
- RaycastHit2D hit = Physics2D.Raycast(transform.position,transform.forward, range);
- if (hit.rigidbody != null) {
- Debug.Log(hit.collider.name);
- if (hit.rigidbody == MyEnemy.GetComponent<Rigidbody>()) {
- Debug.Log("Enemy Found");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement