using System; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.UI; public class LearningUI : MonoBehaviour { public TextMeshProUGUI helpfulGuideText; public Image recoil, moving, verticalPlacement, horizontalPlacement, ammoManagement, overPeeking, allGood, textbox, tracking; public bool showTextFeedback, showGraphicalFeedback; private float currentI = 0; public GameObject legend; public void Start() { var tempColor = recoil.color; tempColor.a = 0f; recoil.color = tempColor; verticalPlacement.color = tempColor; horizontalPlacement.color = tempColor; moving.color = tempColor; tracking.color = tempColor; ammoManagement.color = tempColor; overPeeking.color = tempColor; allGood.color = tempColor; helpfulGuideText.text = ""; showGraphicalFeedback = PlayerPrefs.GetInt("graphicsEnabled") == 1; showTextFeedback = PlayerPrefs.GetInt("textEnabled") == 1; legend.SetActive(false); } public void Update() { var newI = Math.Max(currentI - (Time.deltaTime / 3), 0); helpfulGuideText.color = new Color(helpfulGuideText.color.r, helpfulGuideText.color.g, helpfulGuideText.color.b, newI); currentI = newI; if (Input.GetKeyDown("tab")) { legend.SetActive(true); } if (Input.GetKeyUp("tab")) { legend.SetActive(false); } } private IEnumerator ShowFeedbackImage(Image image, Color color) { image.color = color; for (float i = 1; i >= 0; i -= Time.deltaTime * 0.5f) { helpfulGuideText.color = new Color(helpfulGuideText.color.r, helpfulGuideText.color.g, helpfulGuideText.color.b, i); image.color = new Color(color.r, color.g, color.b, i * 2); yield return null; } } private void ShowFeedbackText(String reason) { if (showTextFeedback) { helpfulGuideText.text = reason; currentI = 1f; } } // these are all the same for now but theyll do different things eventually // coroutine that makes it fade out etc. public void GuideRecoil(String reason, Color color) { StartCoroutine(ShowFeedbackImage(recoil, color)); ShowFeedbackText(reason); } public void GuideMovingWhileShooting(String reason, Color color) { StartCoroutine(ShowFeedbackImage(moving, color)); ShowFeedbackText(reason); } public void GuideTracking(String reason, Color color) { StartCoroutine(ShowFeedbackImage(tracking, color)); ShowFeedbackText(reason); } public void GuideShootingTooFast(String reason, Color color) { helpfulGuideText.text = reason; } public void GuideVerticalCrosshairPlacement(String reason, Color color) { StartCoroutine(ShowFeedbackImage(verticalPlacement, color)); ShowFeedbackText(reason); } public void GuideHorizontalCrosshairPlacement(String reason, Color color) { StartCoroutine(ShowFeedbackImage(horizontalPlacement, color)); ShowFeedbackText(reason); } public void GuideOverpeeking(String reason, Color color) { StartCoroutine(ShowFeedbackImage(overPeeking, color)); ShowFeedbackText(reason); } public void GuideAmmoManagement(String reason, Color color) { StartCoroutine(ShowFeedbackImage(ammoManagement, color)); ShowFeedbackText(reason); } public void GuideSuccess(String reason, Color color) { StartCoroutine(ShowFeedbackImage(allGood, color)); ShowFeedbackText(reason); } }