Player Collision with the bullet
Hello Everyone,
I created a script to kill the player by the computer shooting bullets.
public class PlayerDamage : MonoBehaviour { public int playerHealth=100; private bool isHit=false; void Update () { if (isHit == true) { if (playerHealth >= 1) { playerHealth = playerHealth - 100; isHit = false; } else { Dead (); GameObject.Destroy(this); } } } void OnTriggerEnter(Collider coll){ if (coll.tag=="enemyBullet") { isHit=true; } } private void Dead(){ Application.LoadLevel (0); }
I checked it by checking collision with a bullet tag, but it doesn't work. Player's health doesn't decrease upon collision. I'm using built in first person controller from Unity. What cause this problem? I also tagged the bullet as "enemyBullet" and yes I attached this script to my player.
Your answer
![](https://koobas.hobune.stream/wayback/20220612051529im_/https://answers.unity.com/themes/thub/images/avi.jpg)