using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class CourseItem : MonoBehaviour { // TODO: change to ScriptableObject Course; [Header("ScriptableObject Course")] public string courseTitle; public float courseProgress; public Sprite courseThumbnail; public string courseScene; [Header("UI references")] // Reference to thumbnail object public Image thumbnail; // Reference to title object public TMP_Text title; // Refetence to object so correct callback can be trigger on click public Button button; // Reference to progress bar public GameObject slider; // Reference to `COMPLETED` public GameObject completed; void Start() { // Use public function so that this component can get Instantiated GenerateContent(); } public void GenerateContent() { // Set appearance thumbnail.sprite = courseThumbnail; title.text = courseTitle; // Set progress float progress = Mathf.Clamp01(courseProgress); completed.SetActive(1.0f <= progress); slider.SetActive(0.0f < progress && progress < 1.0f); slider.GetComponent().value = progress; // Add click functionality button.onClick.AddListener(() => SceneManager.LoadScene(courseScene)); } }