- Home /
sword is hitting twice in the first time
my sword is hitting the enemy twice in the first hit ,i tried to fix it by stopping the collider and re using it but it didnt work, i will but my hitting script and my receving damage script.
the hitting script public class hittingsword : MonoBehaviour { private Animator anim; public Collider swordcollider; // Start is called before the first frame update void Start() { anim = gameObject.GetComponent(); }
// Update is called once per frame
void Update()
{
if(Input.GetButtonDown("Fire1"))
{
anim.Play("hitting"); }
}
private void OnCollisionEnter(Collision collision)
{
swordcollider.enabled = false;
}
private void OnCollisionExit(Collision collision)
{
swordcollider.enabled = true;
}
}
the receving damage script
void Update()
{
if (health <= 0)
{
Destroy(this.gameObject);
}
}
private void OnCollisionEnter(Collision collision)
{
if (collision.collider.tag == "sword")
{
//if (info.fullPathHash == playerhittingsword)
{
finaldamgae = (unflixreduce / 100) * damage;
health = health - finaldamgae;
Debug.Log(health);
}
I've had issues similar before because I accidentally had 2 overlapping triggers on my object which were causing the ontriggerenter to call twice., have you checked to make sure the sword doesn't have a similar issue?
thnx it worked ,stupid me put double collider on the enemy
Answer by ProNoob2 · Jul 30, 2019 at 05:06 AM
destroy the object in the OnCollisionEnter()
instead of Update()
i put it before in oncollisionenter but i changed cause i will make a bleeding effect