51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class CourseItem : MonoBehaviour
|
|
{
|
|
[Header("Course")]
|
|
// Reference to the course
|
|
public Course course;
|
|
// Progress of the current user on this course
|
|
public float progress;
|
|
|
|
[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 = course.thumbnail;
|
|
title.text = course.title;
|
|
|
|
// Set progress
|
|
progress = Mathf.Clamp01(progress);
|
|
completed.SetActive(1.0f <= progress);
|
|
slider.SetActive(0.0f <= progress && progress < 1.0f);
|
|
slider.GetComponent<Slider>().value = progress;
|
|
|
|
// Add click functionality
|
|
button.onClick.AddListener(() => SceneManager.LoadScene("Courses/Scenes/Course_0"));
|
|
}
|
|
}
|