Making a Box Collider sword do Damage
Hi, this is my first question on here everyone. Sorry if my formatting is bad, and don't mind if the question is terrible new to 3d development.
So I'm trying to make very simple sword combat in unity 3d for my first-person game, right now I'm using a sword with a box collider with an animation on the sword and a Script on the Enemy to destroy on collision with the swords Box collider and tag. What I'm trying to do is to make the sword do a set amount of damage and have the enemies have an adjustable health amount and turn into a ragdoll on death, No tutorials are helping me with this and I do not know if Raycasts or Colliders are better for a first-person game. if anyone can provide a little help that would be much appreciated
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Sword : MonoBehaviour { Animator anim;
private void Start()
{
anim = GetComponent<Animator>();
}
private void Update()
{
if (Input.GetButtonDown("Fire1"))
anim.SetBool("Attacking", true);
else if(Input.GetButtonUp("Fire1"))
anim.SetBool("Attacking", false);
}
}
Enemy
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class EnemyHealth : MonoBehaviour { // Start is called before the first frame update void Start() {
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Melee")
Destroy(gameObject);
}
}