diff --git a/Scripts/Controls/SegmentedControl.cs b/Scripts/Controls/SegmentedControl.cs index b3fcfe8..2b25a2a 100644 --- a/Scripts/Controls/SegmentedControl.cs +++ b/Scripts/Controls/SegmentedControl.cs @@ -79,16 +79,24 @@ namespace UnityEngine.UI.Extensions { if (selectedSegment) { - selectedSegment.GetComponent().selected = false; + var segment = selectedSegment.GetComponent(); + if (segment) + { + segment.selected = false; + } selectedSegment = null; } } else { + var segment = selectedSegment.GetComponent(); + if (segment) + { #if UNITY_EDITOR - segments[value].GetComponent().StoreTextColor(); + segment.StoreTextColor(); #endif - segments[value].GetComponent().selected = true; + segment.selected = true; + } } } } @@ -164,7 +172,11 @@ namespace UnityEngine.UI.Extensions continue; var sprite = CutSprite(segments[i].image.sprite, i == 0, i == segments.Length - 1); - segments[i].GetComponent().cutSprite = sprite; + var segment = segments[i].GetComponent(); + if (segment) + { + segment.cutSprite = sprite; + } segments[i].image.overrideSprite = sprite; } } @@ -328,7 +340,10 @@ namespace UnityEngine.UI.Extensions { var segment = segmentedControl.selectedSegment.GetComponent(); segmentedControl.selectedSegment = null; - segment.TransitionButton(); + if (segment) + { + segment.TransitionButton(); + } } segmentedControl.selectedSegment = this.button; diff --git a/Scripts/Controls/Stepper.cs b/Scripts/Controls/Stepper.cs index 1a86f1f..1da6af9 100644 --- a/Scripts/Controls/Stepper.cs +++ b/Scripts/Controls/Stepper.cs @@ -174,7 +174,11 @@ namespace UnityEngine.UI.Extensions continue; var sprite = CutSprite(sides[i].image.sprite, i == 0); - sides[i].GetComponent().cutSprite = sprite; + var side = sides[i].GetComponent(); + if (side) + { + side.cutSprite = sprite; + } sides[i].image.overrideSprite = sprite; } }