DNP_ExampleGUI.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Hello user.
  3. *
  4. * This is a script made to teach you how to use the asset.
  5. *
  6. * Use DamageNumberGUI for spawning any popups in screen-space or in a GUI canvas.
  7. * Use DamageNumberMesh for spawning any popups in world-space.
  8. *
  9. * If you need more help, you can check out the documentation.
  10. * Or message me via discord or email.
  11. */
  12. using UnityEngine;
  13. using DamageNumbersPro; // Include DamageNumbersPro Namespace <----- [REQUIRED]
  14. namespace DamageNumbersPro.Demo
  15. {
  16. public class DNP_ExampleGUI : MonoBehaviour
  17. {
  18. public DamageNumber popupPrefab; // Reference DamageNumber Prefab <----- [REQUIRED]
  19. public RectTransform rectTarget;
  20. public Vector2 anchoredPosition;
  21. void Update()
  22. {
  23. if (DNP_InputHandler.GetRightClick())
  24. {
  25. SpawnPopup(Mathf.Round(Random.Range(1, 10)));
  26. }
  27. }
  28. public void SpawnPopup(float number)
  29. {
  30. DamageNumber newPopup = popupPrefab.SpawnGUI(rectTarget, anchoredPosition, number); // Spawn DamageNumber <----- [REQUIRED]
  31. // You can do any change you want on the DamageNumber returned by the Spawn(..) function.
  32. if(Random.value < 0.5f)
  33. {
  34. newPopup.number *= 2;
  35. }
  36. }
  37. }
  38. }