modSelector.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Mirror;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. using UnityEngine.UI;
  7. public class modSelector : MonoBehaviour
  8. {
  9. public Image Bg;
  10. public RectTransform[] mod_images;
  11. Vector2 defaultSize;
  12. public GameObject[] descriptions;
  13. [Scene]
  14. public string[] scenes;
  15. public int currentSelectedId = 0;
  16. public AudioClip selectionSfx;
  17. void Start()
  18. {
  19. if (mod_images.Length != descriptions.Length)
  20. {
  21. Debug.LogError("WHAT THE FUCK ARE YOU DOING");
  22. }
  23. defaultSize = mod_images[0].sizeDelta;
  24. }
  25. // Update is called once per frame
  26. void Update()
  27. {
  28. for (int i = 0; i < mod_images.Length; i++)
  29. {
  30. if(i == currentSelectedId)
  31. {
  32. mod_images[i].sizeDelta = Vector2.Lerp(mod_images[i].sizeDelta, defaultSize * 1.5f, 0.1f);
  33. descriptions[i].SetActive(true);
  34. }
  35. else
  36. {
  37. mod_images[i].sizeDelta = Vector2.Lerp(mod_images[i].sizeDelta, defaultSize, 0.1f);
  38. descriptions[i].SetActive(false);
  39. }
  40. }
  41. }
  42. public void OnPointerEnter(int value)
  43. {
  44. currentSelectedId = value;
  45. FindObjectOfType<loadingScreen>().setScene(scenes[value]);
  46. Bg.sprite = mod_images[value].GetComponent<Image>().sprite;
  47. playSelectedSound();
  48. }
  49. public void OnPointerExit()
  50. {
  51. //currentSelectedId = -1;
  52. }
  53. public void playSelectedSound()
  54. {
  55. GetComponent<AudioSource>().PlayOneShot(selectionSfx);
  56. }
  57. }