Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6. public class ShowArray : MonoBehaviour
  7. {
  8.  
  9. public float[] array;
  10. public int arrayLn;
  11.  
  12. public GameObject spritePrefab;
  13. private ArrayGenerator d;
  14. public GameObject[] arrayObj;
  15. public GameObject holder;
  16. void Start()
  17. {
  18. d = GetComponent<ArrayGenerator>();
  19. arrayObj = new GameObject[arrayLn];
  20. array = d.GenerateArray(array, arrayLn);
  21. for (int i = 0; i < arrayLn; i++)
  22. {
  23. arrayObj[i] = Instantiate(spritePrefab, new Vector3(i, 0, 0), Quaternion.identity, holder.transform);
  24. }
  25. }
  26. void Update()
  27. {
  28. if (Input.GetKey(KeyCode.D))
  29. {
  30. array = d.SortArray(array, arrayLn);
  31. }
  32. if (Input.GetKey(KeyCode.F))
  33. {
  34. PrintArray();
  35. }
  36. }
  37.  
  38. public void PrintArray()
  39. {
  40. for (int i = 0; i < arrayLn; i++)
  41. {
  42. arrayObj[i].GetComponent<SpriteRenderer>().color = new Color(array[i], array[i], array[i]);
  43. arrayObj[i].GetComponentInChildren<TextMesh>().text = Math.Round(array[i], 3).ToString();
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement