- Home /
Can't manage to damage enemies...
I am sorry for so much redundancy, but I can't kill my enemy and there is no reason I can see.
GameObject GestureAttack()
{
invincible = true;
GameObject[] Foes = GameObject.FindGameObjectsWithTag("Foe");
GameObject closest = null;
float distance = Mathf.Infinity;
Vector3 position = transform.position;
s_PlayerControl enemyHealth = GetComponent<s_PlayerControl>();
foreach (GameObject go in Foes)
{
FoeCurrentHealth = go.GetComponent<s_EnnemyControl>().FoeCurrentHealth;
Debug.Log(FoeCurrentHealth);
Vector3 diff = go.transform.position - position;
float curDistance = diff.sqrMagnitude;
if (curDistance < distance)
{
closest = go;
distance = curDistance;
}
}
Here is my problem (Took is log). But even with a substraction I can't damage them.
if (recupgeste == "D" && recupgestescore > 0.60 || Input.GetKeyDown(KeyCode.Space))
{
transform.position = Vector3.MoveTowards(transform.position, closest.transform.position, 100);
// foreach (GameObject go in Foes)
//{
Debug.Log(enemyHealth.FoeCurrentHealth);
if (FoeCurrentHealth >0)
{
Debug.Log("TOOK");
enemyHealth.TakeDamage(attackDamage);
//}
}
}
return closest;
}
They always have one point of life....
Comment
Answer by nopogo · May 04, 2016 at 01:48 PM
You log the enemyHealth.FoeCurrentHealth but the var you use in the if-statement is FoeCurrentHealth. Looks like one of these should be the other.
Your answer
Follow this Question
Related Questions
Attack selected Enemy Turn Based Combat 2 Answers
How to have an NPC with multiple parts detect damage 1 Answer
Collision Damage 1 Answer
(C#) Enemy health and take damage from bullets 1 Answer
Rapid fire does damage every frame 0 Answers