- Home /
Question by
Orion_Reed · Dec 01, 2017 at 03:19 PM ·
c#if-statementsbestpracticesrecursion
A better way to write a recursive if statement like this mess?
I know there must be a much cleaner way of checking X levels down for this if statement, it's just bugging me so much that I'm using such a sloppy if statement as this is clearly not the way to find out what I'm trying to find out.
Weapon is a ScriptableObject that can reference other weapons to emit in the explosion.
if (Weapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon.SubWeapon && Weapon != Weapon.SubWeapon)
{
EditorGUILayout.HelpBox("This weapon has more than " + Weapon.SubRecursionMax + "recursive levels.", MessageType.Warning);
}
else if (Weapon = Weapon.SubWeapon)
{
EditorGUILayout.HelpBox("This weapons is infinitely recursive.", MessageType.Error);
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Trying to Recreate Transform Child Heirarchy to a List 2 Answers
Where to run InvokeRepeating? 1 Answer
Am I coding wrong for Unity C#? 2 Answers