private void Start() { //BackgroundImage = Background.GetComponent<Image>(); BackgroundTransform = Background.GetComponent <RectTransform>(); foregroundImage = Foreground.GetComponent <Image>(); foregroundTransform = Foreground.GetComponent <RectTransform>(); // Get quality grades for shop level 3. grades = new LinkedList <Quality.QualityGrade>(Quality.GetPossibleGrades(3)); // Pop the current grade. //currentGrade = grades.First.Value; currentGrade = StartingGrade; //grades.RemoveFirst(); // Initialize with details. TextCurrentLevel.text = Quality.GradeToString(currentGrade); TextCurrentLevel.color = Quality.GradeToColor(currentGrade); foregroundImage.color = Quality.GradeToColor(currentGrade); fillAmount = StartFill; // POSITIONING FOREGROUND BAR. // Foreground bar min/max derived from the background. // These are inverted from what you would expect because of Unity anchors. // barMaxWidth = 0.0 -> barMinWidth = 1.0; barHeight = BackgroundTransform.rect.height - Padding * 2f; barMaxWidth = Padding * 2f; barMinWidth = BackgroundTransform.rect.width + Padding * 2f; // Position the middle of the bar correctly in almost all circumstances. Vector3 pos = foregroundTransform.anchoredPosition; //pos.x = -Padding; pos.x = Padding; foregroundTransform.anchoredPosition = pos; // Fill initial correctly. //foregroundTransform.sizeDelta = new Vector2(-barMaxWidth, barHeight); float fill = -Mathf.Lerp(barMinWidth, barMaxWidth, fillAmount); foregroundTransform.sizeDelta = new Vector2(fill, barHeight); // Subscribe to countdown tick. Countdown.onTick += SubtractFixed; }