You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.7 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TMPro.Examples
  4. {
  5. public class TextMeshSpawner : MonoBehaviour
  6. {
  7. public int SpawnType = 0;
  8. public int NumberOfNPC = 12;
  9. public Font TheFont;
  10. private TextMeshProFloatingText floatingText_Script;
  11. void Awake()
  12. {
  13. }
  14. void Start()
  15. {
  16. for (int i = 0; i < NumberOfNPC; i++)
  17. {
  18. if (SpawnType == 0)
  19. {
  20. // TextMesh Pro Implementation
  21. //go.transform.localScale = new Vector3(2, 2, 2);
  22. GameObject go = new GameObject(); //"NPC " + i);
  23. go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.5f, Random.Range(-95f, 95f));
  24. //go.transform.position = new Vector3(0, 1.01f, 0);
  25. //go.renderer.castShadows = false;
  26. //go.renderer.receiveShadows = false;
  27. //go.transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
  28. TextMeshPro textMeshPro = go.AddComponent<TextMeshPro>();
  29. //textMeshPro.FontAsset = Resources.Load("Fonts & Materials/LiberationSans SDF", typeof(TextMeshProFont)) as TextMeshProFont;
  30. //textMeshPro.anchor = AnchorPositions.Bottom;
  31. textMeshPro.fontSize = 96;
  32. textMeshPro.text = "!";
  33. textMeshPro.color = new Color32(255, 255, 0, 255);
  34. //textMeshPro.Text = "!";
  35. // Spawn Floating Text
  36. floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
  37. floatingText_Script.SpawnType = 0;
  38. }
  39. else
  40. {
  41. // TextMesh Implementation
  42. GameObject go = new GameObject(); //"NPC " + i);
  43. go.transform.position = new Vector3(Random.Range(-95f, 95f), 0.5f, Random.Range(-95f, 95f));
  44. //go.transform.position = new Vector3(0, 1.01f, 0);
  45. TextMesh textMesh = go.AddComponent<TextMesh>();
  46. textMesh.GetComponent<Renderer>().sharedMaterial = TheFont.material;
  47. textMesh.font = TheFont;
  48. textMesh.anchor = TextAnchor.LowerCenter;
  49. textMesh.fontSize = 96;
  50. textMesh.color = new Color32(255, 255, 0, 255);
  51. textMesh.text = "!";
  52. // Spawn Floating Text
  53. floatingText_Script = go.AddComponent<TextMeshProFloatingText>();
  54. floatingText_Script.SpawnType = 1;
  55. }
  56. }
  57. }
  58. }
  59. }