Meele Script

I’m looking for a good way to write a meele script. For now I have something like that

using UnityEngine;
using System.Collections;

public class MyHand : MonoBehaviour {

    float Distance;
    RaycastHit hit;
   
    void Update () {
        if (Input.GetButton("Fire1")) {
            audio.Play();
            Vector3 forward = transform.TransformDirection (Vector3.forward);
            Distance = hit.distance;
            if (Distance <= 2) {
                hit.transform.SendMessage("ApplyDamage", 50, SendMessageOptions.DontRequireReceiver);
            }
        }
    }

}

but it’s pointing only at one point which is kinda inconvenient. Especially if the player swings his fist all across the whole screen^^

I suggest you go watch a tutorial on raycasts. You can also watch brackeys survival game tutorial, it should help quiet abit.

That’s exactly what I’m trying not to use and hat’s why I asked if there is another way to do it.

Look at Physics.Overlapsphere and Vector3.Angle

Using these you can get all things hit within an arc. Basically doing this: