- Home /
Display 1 No cameras rendering when player collides with enemy
Hi there,
My player collides with an enemy, at the moment the only thing that happens is that they lose 1 health. However, as soon as I touch an enemy that message comes up on screen. The enemy's hitbox is set as a trigger. The camera is attached to the player. This is is the related script:
//enemy "attack"
void OnTriggerEnter2D(Collider2D collision)
{
Health playerhealth = collision.GetComponent<Health>();
if (playerhealth != null)
{
print("hit");
playerhealth.TakeDamage(1);
}
}
//player takes damage
public void TakeDamage(int dmg)
{
health -= dmg;
print("damage taken");
}
Both 'hit' and 'damage taken' are printed to the console before the message appears. Any help would be hugely appreciated.
Thanks
Answer by ray2yar · Jan 19, 2019 at 11:11 PM
Your problem isn't in the code you posted. Something else is going on. Do you have other related code? Does something happen when the health gets to a certain point? Is the character still active in the scene (check the scene view and hierarchy) ?