using System.Collections; using System.Collections.Generic; using UnityEngine; using…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
/// /// Manages the BoostSlider. This should connect to the Slider component and set /// its value based on PlaneControls.BOOST_RECHARGE_U. /// You should also set the color of the slider based on its value. /// [RequireComponent(typeof(Slider))] [DisallowMultipleComponent] public class BoostSlider : MonoBehaviour { [Header("Inscribed")] public Color rechargeColor = Color.red; public Color readyColor = Color.green; public Image fillImage;
Slider slid; void Start() { // Set slid to the Slider component attached to this GameObject } void FixedUpdate() { // Set slid.value to PlaneControls.BOOST_RECHARGE_U // Set fillImage.color to readyColor if BOOST_RECHARGE_U == 1 // Otherwise, set fillImage.color to rechargeColor // Try using a "ternary operator": e.g., bool b = (u==1) ? true : false; }} Fill out the code for the comments listed under the Start() and FixedUpdate() functions
- Assistant
void Start() { slid = GetComponent(); // Set slid to the Slider component attached to this GameObject }
void FixedUpdate() { slid.value = PlaneControls.BOOST_RECHARGE_U; // Set slid.value to PlaneControls.BOOST_RECHARGE_U
fillImage.color = (PlaneControls.BOOST_RECHARGE_U == 1) ? readyColor : rechargeColor; // Set fillImage.color to readyColor if BOOST_RECHARGE_U == 1, otherwise set it to rechargeColor}