Hallo everyone
i am a beginner and i have been doing unity for just 2 weeks,.
i am trying to lat the enemy’s apply damage to my character.
i just doesnt work, but i dont know why, the void Explode is called when the enemy has the same position as thr character. it just doenst apply damage. can anyone help me?
Player Code:
public int Phealth = 100;
public GameObject KillEffect;
public void PTakeDamage(int Pdamage)
{
Phealth = Phealth - Pdamage;
if (Phealth <= 0)
{
PlayerDie();
}
}
void PlayerDie()
{
//Instantiate(KillEffect, transform.position, Quaternion.identity);
Destroy(this.gameObject);
}
{
Enemy Code:
public int health = 100;
public GameObject deathEffect;
public GameObject ExplodeEffect;
private Transform Player;
public Player player;
public int Pdamage = 1;
void Start()
{
Player = GameObject.FindGameObjectWithTag("Player").GetComponent<Transform>();
}
void Update()
{
if (this.gameObject.transform.position == Player.transform.position)
{
Explode();
}
}
void Explode()
{
//Instantiate(ExplodeEffect, transform.position, Quaternion.identity);
player.PTakeDamage(Pdamage);
Destroy(gameObject);
}
}