#Working with lists

1 messages · Page 1 of 1 (latest)

errant pulsar
#

I don't get it...
Why wouldn't this just look like:

public void PerformLogic() {
  PositionElements();
  health.fontSize = reference;
}

public void PositionElements()
{
  for(int i = 0; i < elements.Count; i++) {
    var rt = (RectTransform)elements[i].transform;
    rt.anchoredPosition = new Vector2(reference * (i * 3), reference);
    rt.sizeDelta = whatever;
  }
}```
tall orbit
#

but from what I've found online there is no workaround of just using list to assign values to variables, I'll have to do it manually so I can avoid any problems later

errant pulsar
#

There is no logical connection between how you position these elements, why would you put them in a list?

#

It's all just magic numbers

tall orbit
#

I was trying to avoid that in the first place but it turns out it's not making anything easier after all

errant pulsar
#

I find the whole thing very odd because it seems like you're referencing things you don't actually care about. Why reference the GameObject of the health icon if you're not directly using it?
If you did care about the child RectTransforms of so many objects, why not just say
[SerializeField] private RectTransform healthIcon, health, armourIcon, armour, timerIcon, timer, jetpackIcon, hookIcon, flashlightIcon;
Then drag and drop those child transforms into the inspector, and do the positioning logic on them.

#

If you care about the text on the armour, have
[SerializeField] private TextMeshProUGUI armourText, timer;

tall orbit
#

also I do need those things outside of the list which can also be seen in my code but it's commented because of an error and I mentioned it before

errant pulsar
#

If you care about multiple objects in a similar way, make a script that you reference on the object that groups that logic together.
Say if you cared about the root object, the child, and some text:

public class TextGroup : MonoBehaviour {
  public RectTransform Child;
  public TextMeshProUGUI Text;
}```
Then you reference 
`[SerializeField] private TextGroup armourText, timer;`
to easily get `armorText.gameObject`, `armorText.Child`, or `armorText.Text`
#

If you want to automate the discovery of those objects, assign them in Awake of the TextGroup class

tall orbit
#

I asked a simple question, was it possible to assign values to vars in list or no. I already know how lists work, how to get different types of components, how to use sf and all that, my question was very direct and could've been answered in 1 word yes/no

errant pulsar
#

Great, happy to help then

tall orbit
#

I appreciate you trying to help and explain all of this but I really don't need it and I am in a hurry to finish this code