Collider.enabled not functioning correctly
Here's my code
void TrySwing(){
if (Input.GetMouseButtonDown(0) && Time.time > nextSwing){
nextSwing = Time.time + swingTimer;
playerAnims.SetBool("isSwinging", true);
weapon.GetComponent<MeshCollider>().enabled = true;
swingAudio.Play();
}
if (Input.GetMouseButtonUp(0) || nextSwing < Time.time){
playerAnims.SetBool("isSwinging", false);
weapon.GetComponent<MeshCollider>().enabled = false;
}
}
All I want it to do is enable the collider on mouse click down, then disable it on release, but at runtime the collider component immediately and permanently disables, with no console errors or warnings to speak of. The animation code above, and sound code below the Collider.enabled statement both execute correctly, so the if statement conditions are being satisfied. I don't understand why the collider won't enable.
Try Get$$anonymous$$ouseButton() (holding mouse down) to enable, and Get$$anonymous$$ouseButtonUp() (release) to disable.
Your answer
![](https://koobas.hobune.stream/wayback/20220612184847im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[SOLVED]My OnMuseDown execute only once 1 Answer
First person shooter : Leaning! 2 Answers
NavMesh of an automatically generated maze 0 Answers
example of new way to load levels 1 Answer
Menu object not responding 0 Answers