- Home /
Question by
tanerismail12345 · Jul 20, 2021 at 11:39 AM ·
colliderenabled
Collider.Enabled error: true and then false loop
am trying to make my animated enemy (child object) disable its collider once enemieDeath == true. I wrote a debug.log and it says "Collider. Enabled = true, Collider. Enabled = false, it does this in an endless loop after my player collides with the enemie child (which has animation).
This is the script I am using.
EnemieMove Script
//References PlayerController Script
if (playerControllerScript.enemieDeath == true)
{
goblinCollider.enabled = !goblinCollider.enabled;
enemieAnimator.SetBool("IsDead", true);
Debug.Log("Collider.enabled = " + goblinCollider.enabled);
}
}
Player Controller Script
void FixedUpdate()
{
int layerMask = 1 << 8;
int layerMaskCollectable = 1 << 9;
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.down), out hit, 1.5f, layerMask))
{
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.down) * hit.distance, Color.yellow);
Debug.Log("Did Hit");
enemieDeath = true;
//Destroy(hit.transform.gameObject);
playerRb.AddForce(Vector3.up * bounceForce, ForceMode.Impulse);
gameManager.UpdateScore(20);
}
Comment