- Home /
no errors, but not working?
I have the following scripts. My basic objective is for when the player reaches a certain distance to the enemy and then right clicks he'll start attacking and at the end of each attack animation, damage will be applied to the enemy's health. So I have the following scripts and I have no errors. It's just that nothing is working - health not updating, not animating, etc.
//Enemy Script
public float totalHealth = 100F;
public void UpdateHealth(float adj)
{
totalHealth -= adj;
}
///END OF SCRIPT
//Player Script
public Enemy enemyScript;
public Transform enemy;
public float maxDistance = 4F; //max distance from player to enemy
public float autoAttackDamage = 50F;
void AttackingAnimation()
{
float distanceBetween = Vector3.Distance(transform.position, enemy.transform.position);
if(Input.GetMouseButton(1))
{
if(distanceBetween < maxDistance)
{
animation["Attack"].speed = 0.75F;
animation["Attack"].wrapMode = WrapMode.Loop;
animation.Play("Attack");
}
}
Debug.Log("Distance is: " + distanceBetween);
}
IEnumerator Attack()
{
if(animation.IsPlaying("Attack"))
yield return new WaitForSeconds(animation["Attack"].length);
//updates enemey's health at the end of the attack animation
enemyScript.UpdateHealth(-autoAttackDamage);
}
Answer by tanoshimi · Jan 26, 2015 at 09:59 PM
a.) Please format your code. It makes it very hard for people to help when we can't see properly.
b.) Why would your health update or your enemy attack? From what I can see, nothing ever calls UpdateHealth()
, AttackingAnimation()
or Attack()
....
I didn't copy the entire script, I have an update method that calls each the functions I've listed.
Your answer
Follow this Question
Related Questions
Editing UIElements Label through code and alignment 1 Answer
How to disable a script on a bunch of instantiated objects with tag ? 1 Answer
urp custom shader? 0 Answers
Help required for shutting down compiled App 0 Answers
Keep music playing when i reset a scene but stop it when i change scene 1 Answer