changeEffects.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class changeEffects : MonoBehaviour
  6. {
  7. public GameObject[] effects;
  8. private GameObject currentObject;
  9. private int currentObjectID = 0;
  10. public GameObject guiTextLink;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14. currentObject = Instantiate(effects[currentObjectID]);
  15. guiTextLink.GetComponent<Text>().text = effects[currentObjectID].name;
  16. }
  17. // Update is called once per frame
  18. void FixedUpdate()
  19. {
  20. if (Input.GetKeyDown(KeyCode.RightArrow))
  21. NextEffect();
  22. if (Input.GetKeyDown(KeyCode.LeftArrow))
  23. PrevEffect();
  24. }
  25. public void NextEffect()
  26. {
  27. if (currentObjectID < effects.Length - 1)
  28. {
  29. Destroy(currentObject);
  30. currentObject = Instantiate(effects[++currentObjectID]);
  31. guiTextLink.GetComponent<Text>().text = effects[currentObjectID].name;
  32. }
  33. }
  34. public void PrevEffect()
  35. {
  36. if (currentObjectID > 0)
  37. {
  38. Destroy(currentObject);
  39. currentObject = Instantiate(effects[--currentObjectID]);
  40. guiTextLink.GetComponent<Text>().text = effects[currentObjectID].name;
  41. }
  42. }
  43. public void RefreshEffect()
  44. {
  45. Destroy(currentObject);
  46. currentObject = Instantiate(effects[currentObjectID]);
  47. }
  48. }