I have enemyDamage defined in another script so why wont this work? Help please!
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public int playerHealth = 100;
bool dead = false;
void OnColliderHit()
{
if (gamobjectWithTag ("Enemy"))
{
playerHealth - enemyDamage;
}
}
void Update()
{
if (playerHealth <= 0)
dead == true;
if(dead == true)
{
Application.LoadLevel(Application.LoadedLevel);
}
}
}
public class PlayerHealth : MonoBehaviour {
public int playerHealth = 100;
bool dead = false;
void OnCollisionEnter(Collider other)
{
if (other.gameObject.tag == "Enemy")
{
enemyDamage = other.getComponentInChildren<EnemyScript>().damage;
playerHealth = playerHealth - enemyDamage;
}
}
void Update()
{
if(playerHealth <= 0){
dead = true;
Application.LoadLevel(Application.LoadedLevel);
}
}
}
Then to all Enemy’s you attach a script like
public class EnemyScript : MonoBehavior{
public int damage = 10;
}
Try to analyze the code, there are several mistakes you made, but this way it should work.