- Home /
Script Wont Take away health from my player when hit by enemy bullet.
Hi all
Im having a problem where my script wont take away health by my player if it is hit by the enemy bullet, the script has been placed on my character and when hit with anything with the Tag "enemyBullet" it should take health away from my character.
Thanks for any help you can offer.
I am a complete noob at this so if you are going to offer advice please try explain it as simply as possible. Thanks!
pragma strict
var health : int = 100;
var damage : int = 20;
var whiteStencilGui : GUISkin;
function Start () {
}
function Update () {
}
function OnCollisionEnter (collision : Collision)
{
if(collision.collider.tag == "enemyBullet")
{
health = health - damage;
}
}
function OnGUI()
{
GUI.skin = whiteStencilGui;
GUI.Box (Rect (Screen.width-100, 10, 100, 50), "health:" +health);
}
where you shoot your bullet and maybe it is not even colliding so put a debug in your onCollisionEnter just to make sure something hits it
Your game object may be going to fast for the collision/physics system to pick up on it.
If you can answer these questions it will help us to have an idea why.
Are you using a CharacterController?
Does the player game object have a collider, and if so, is it set as a Trigger collider?
Does the bullet game object have a collider?
Does the bullet game object have a rigidbody?
Your answer
Follow this Question
Related Questions
Lose health on collision 1 Answer
Player Health 3 Answers
Adding a counter? 1 Answer
Enemy health not decreasing 1 Answer