Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class ShowArray : MonoBehaviour
- {
- public float[] array;
- public int arrayLn;
- public GameObject spritePrefab;
- private ArrayGenerator d;
- public GameObject[] arrayObj;
- public GameObject holder;
- void Start()
- {
- d = GetComponent<ArrayGenerator>();
- arrayObj = new GameObject[arrayLn];
- array = d.GenerateArray(array, arrayLn);
- for (int i = 0; i < arrayLn; i++)
- {
- arrayObj[i] = Instantiate(spritePrefab, new Vector3(i, 0, 0), Quaternion.identity, holder.transform);
- }
- }
- void Update()
- {
- if (Input.GetKey(KeyCode.D))
- {
- array = d.SortArray(array, arrayLn);
- }
- if (Input.GetKey(KeyCode.F))
- {
- PrintArray();
- }
- }
- public void PrintArray()
- {
- for (int i = 0; i < arrayLn; i++)
- {
- arrayObj[i].GetComponent<SpriteRenderer>().color = new Color(array[i], array[i], array[i]);
- arrayObj[i].GetComponentInChildren<TextMesh>().text = Math.Round(array[i], 3).ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement