I have come across a lot of people that have had this error, however I haven't been able to fix the error myself. I am simply trying to have an enemy collider deal damage to my player.
Player:
public class PlayerHealth : MonoBehaviour {
public int maxHealth = 100;
private int currentHealth;
void Awake()
{
currentHealth = maxHealth;
}
void Start ()
{
print (currentHealth);
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Enemy")
{
currentHealth -= GetComponent ().enemyDamage;
//currentHealth -= GetComponent ().enemyDamage;
Debug.Log("You have been hit!" + currentHealth);
}
}
}
And for the enemy:
public class EnemyStats : MonoBehaviour {
public int maxHealth = 100;
private int currentHealth;
public int enemyDamage = 10;
public int armorRating = 10;
void Awake()
{
currentHealth = maxHealth;
}
public void Damage(int gunDamageAmount)
{
currentHealth -= gunDamageAmount - armorRating;
if (currentHealth <= 0f)
{
gameObject.SetActive (false);
Debug.Log ("Enemy killed!");
}
}
}
↧