DNP_ExampleMesh.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_ExampleMesh : MonoBehaviour
  17. {
  18. public DamageNumber popupPrefab; // Reference DamageNumber Prefab <----- [REQUIRED]
  19. public Transform target;
  20. void Update()
  21. {
  22. if(DNP_InputHandler.GetLeftClick())
  23. {
  24. SpawnPopup(Mathf.Round(Random.Range(1, 10)));
  25. }
  26. }
  27. public void SpawnPopup(float number)
  28. {
  29. DamageNumber newPopup = popupPrefab.Spawn(target.position + new Vector3(0, 0.25f, -1), number); // Spawn DamageNumber At Target <----- [REQUIRED]
  30. // You can do any change you want on the DamageNumber returned by the Spawn(..) function.
  31. // The following code is [OPTIONAL] just to show you some examples
  32. // Let's make the popup follow the target
  33. newPopup.SetFollowedTarget(target);
  34. // Let's check if the number is greater than 5
  35. if (number > 5)
  36. {
  37. // Let's increase the popup's scale
  38. newPopup.SetScale(1.5f);
  39. // Let's change the color of the popup
  40. newPopup.SetColor(new Color(1, 0.2f, 0.2f));
  41. }
  42. else
  43. {
  44. // The following lines reset the changes above
  45. // This would only be neccesary for pooled popups
  46. newPopup.SetScale(1);
  47. newPopup.SetColor(new Color(1, 0.7f, 0.5f));
  48. }
  49. // Flip the target
  50. target.GetComponent<DNP_Target>().Hit();
  51. }
  52. }
  53. }