ETFXButtonScript.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. namespace EpicToonFX
  7. {
  8. public class ETFXButtonScript : MonoBehaviour
  9. {
  10. public GameObject Button;
  11. Text MyButtonText;
  12. string projectileParticleName; // The variable to update the text component of the button
  13. ETFXFireProjectile effectScript; // A variable used to access the list of projectiles
  14. ETFXProjectileScript projectileScript;
  15. public float buttonsX;
  16. public float buttonsY;
  17. public float buttonsSizeX;
  18. public float buttonsSizeY;
  19. public float buttonsDistance;
  20. void Start ()
  21. {
  22. effectScript = GameObject.Find("ETFXFireProjectile").GetComponent<ETFXFireProjectile>();
  23. getProjectileNames();
  24. MyButtonText = Button.transform.Find("Text").GetComponent<Text>();
  25. MyButtonText.text = projectileParticleName;
  26. }
  27. void Update ()
  28. {
  29. MyButtonText.text = projectileParticleName;
  30. // print(projectileParticleName);
  31. }
  32. public void getProjectileNames() // Find and diplay the name of the currently selected projectile
  33. {
  34. // Access the currently selected projectile's 'ProjectileScript'
  35. projectileScript = effectScript.projectiles[effectScript.currentProjectile].GetComponent<ETFXProjectileScript>();
  36. projectileParticleName = projectileScript.projectileParticle.name; // Assign the name of the currently selected projectile to projectileParticleName
  37. }
  38. public bool overButton() // This function will return either true or false
  39. {
  40. Rect button1 = new Rect(buttonsX, buttonsY, buttonsSizeX, buttonsSizeY);
  41. Rect button2 = new Rect(buttonsX + buttonsDistance, buttonsY, buttonsSizeX, buttonsSizeY);
  42. if(button1.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)) ||
  43. button2.Contains(new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y)))
  44. {
  45. return true;
  46. }
  47. else
  48. return false;
  49. }
  50. }
  51. }