I think My code is slightly better :)

I think My code is sligthly better :slight_smile:

void AimWeapon()
{
    float targetDistance = Vector3.Distance(transform.position, target.transform.position);
    weapon.transform.LookAt(target.transform);

    Attack(targetDistance < range);
}

void Attack(bool isActive)
{
    var myEmission = myParticleSystem.emission;
    myEmission.enabled = isActive;
}
1 Like

Better is subjective. There are different coding styles, and unless performance is actually improved it’s more a matter of taste on how you prefer your code written. For example I perfer having a scripts folder rather than a general folder for each GameObjects type, if I’m able to/my team is able to work with the code base how we are agree with; that’s much more performant than the “objective best way”.
(Sorry for the rant, but I dislike seeing online posts like on Youtube saying that they “Fixed” a game mechanic or idea).

You’re way is a good way of going about it. Another option could be caching the Emission system in a private member variable instead of assigning it in memory each time. (As I said, my suggestion is negliable but just something I would prefer doing. You keep improving as you see best, you’re doing good!)

1 Like

Privacy & Terms