Hey everyone,
I have a problem with a code I’ve written to sort images from the new UI system in a scoreboard-like list. The images all have a number value of which number they are of all added images (eg. the first image ever is 0, the one created after it is 1, etc.) and a score value, which I want to use for the sorting.
So far, this is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class scoreboard : MonoBehaviour {
float myValue;
float myScore;
float oldY;
void Start () {
myScore = float.Parse (transform.GetChild (1).transform.GetChild (0).GetComponent<Text> ().text);
myValue = float.Parse (transform.name.Substring(24));
transform.localPosition = new Vector3(-10f, -780f + 64 * (myScore - 1f), 0f);
}
void Update () {
myScore = float.Parse (transform.GetChild (1).transform.GetChild (0).GetComponent<Text> ().text);
myValue = float.Parse (transform.name.Substring(transform.name.Length-1));
for(int i = 0; i <= myValue-1; i+=1){
GameObject newGO = GameObject.Find("StudentDataPrefab(Clone)" + (i).ToString());
if(transform.localPosition.y == newGO.transform.localPosition.y){
transform.localPosition = new Vector3(newGO.transform.localPosition.x + 60f, -780f + 64 * (myScore - 1f), 0f);
}
}
if (oldY != transform.localPosition.y) {
oldY = transform.localPosition.y;
transform.localPosition = new Vector3(-10f, -780f + 64 * (myScore - 1f), 0f);
}
}
}
I don’t know what’s wrong here, because it works with the first 9 images in the list, but the vertical sorting stops working from the 10th image.
I hope someone can help me here!