Player health not decreasing, please help
My player health doesn't decrease when it collides with an enemy, please help. Code is sampled below: using UnityEngine; using System.Collections;
public class PlayerDeathOnTouch : MonoBehaviour
{
public float playerHealth = 100;
void OnControllerColliderHit(ControllerColliderHit hit)
{
if(hit.gameObject.tag == "Enemy")
{
playerHealth = playerHealth -100;
}
}
}
The first step is to know exactly where the problem starts, did you put a Debug.log inside your function and inside your if block ?
1) Is the OnControllerColliderHit function called ? => put a Debug.Log at the first line of the function to know that. If it's called, who is the "hit" object ? => Debug.Log(hit.gameobject.name) to know if the hit object is actually the object you expect. If the object is your enemy, Debug.Log in the if block to know if the condition hit.gameObject.tag == "Enemy" is true.
2) If all the steps above are ok, so how do you know the player health is the problem ? Is the value displayed somewhere ? The problem could start later in the code steps, and not in this OnControllerColliderHit function.
Your answer
Follow this Question
Related Questions
GUI Texture slide down || Clipping mask. 0 Answers
Touch control swipe up to jump 1 Answer
My enemy is not taking damage... 3 Answers
Do Death Function Only Once. 2 Answers
Low Energy Wearable Device with Bluetooth 4 : how to integrate it into Unity 3D ? 0 Answers