Is this a glitch??? My attackCooldown float rounding to 1, only when I use a variable. Works if I hard code in the value
I've debugged, troubleshot, and done all I could to figure out what's going. If somebody has an answer PLEASE help.
in the Attack() function the attackCooldown always comes out as 1, as long as I divide by any variable. I can hard code in the value 100 and it will come out with the correct value but as soon as I assign a variable to hold 100 the value starts coming out as one again.
public class CharacterCombat : MonoBehaviour {
 public float attackSpeed = 100f;
 private float attackCooldown = 0f;
 CharacterStats myStats;
 void Start(){
     myStats = GetComponent <CharacterStats> ();
     //attackSpeed = myStats.attackSpeed.GetValue ();
 }
 void Update(){
     attackCooldown -= Time.deltaTime;
 }
 public void Attack(CharacterStats targetsStats){
     if (attackCooldown <= 0f) {
         targetsStats.TakeDamage (myStats.damage.GetValue ());
         attackCooldown = (1f / attackSpeed);
     }
 }
 
               }
This method is being used for my player to attack and if I hard code in the numbers he can attack as correctly but can only attack once a second otherwise. Also I've tried everything I can think of. Thanks!
Answer by CStampGames · Oct 29, 2017 at 07:45 PM
solved it. I was calling the attack function from the wrong instance of the class
Your answer