if (GetComponentInChildren<tk2dSprite>() == null) { var sprite = GetComponentInChildren<tk2dSlicedSprite>(); } else { var sprite = GetComponentInChildren<tk2dSprite>(); } //Вот начиная отсюда, sprite подкрашиваться красным. (does not exist) var joyWorldTopRight = sprite.transform.TransformPoint(sprite.GetBounds().max); var joyScreenTopRight = BattleGUI.Instance.GuiCamera.WorldToScreenPoint(joyWorldTopRight); var joyWorldBottomLeft = sprite.transform.TransformPoint(sprite.GetBounds().min); var joyScreenBottomLeft = BattleGUI.Instance.GuiCamera.WorldToScreenPoint(joyWorldBottomLeft); Of course, the entire lower part of the code can be put into a separate method, or it can simply be duplicated - something is not particularly good, dubbing the code and an extra method call on level ground. Are there alternatives?
ifcondition the variabledynamiс spritenot an option? - Alexey Shimansky