Throttling our attacks question

Just wondering, if I implement the check before accessing AttackBehavior (shown below) is that going to cause any issues? I feel like it’s saving a bit of resources by performing the check before accessing the method. Just curious, thank you!

            else
            {
                GetComponent<Mover>().Cancel();
                if (timeSinceLastAttack > timeBetweenAttacks)
                {
                    AttackBehavior();
                }
            }
        }

        private void AttackBehavior()
        {
            GetComponent<Animator>().SetTrigger("isAttacking");
            timeSinceLastAttack = 0;

        }

In both cases, the meaty part of what we’re doing is if(timeSinceLastAttack>timeBetweenAttacks). I’m not sure a profiler would detect much in the way of a difference.
Both ways work, so there shouldn’t be any issues.

Thank you! It didn’t cause any issues besides me having to think of a clever way to handle the AI’s movement between points because I hadn’t included a function Rick ended up re-using.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms