So i have this piece of code that is working like i want it to but its rather cumbersome. I wonder if there is a way to do this with a loop since al the lines are kinda the same except for some minor differences. If there is a way to use variables for these minor differences so i dont have to copy them manually it would be very nice.
Here is the code:
public void UpdateMenu(){
Delay = 0;
if (CurrentScroll > (Player.Inventory.Count-1)){
Line1.text = "Nothing here scrub.....";
}
else {
Line1.text = Player.Inventory[0+CurrentScroll].amount + " units of " + Player.Inventory[0+CurrentScroll].name;
ResSp1.sprite = IDB.itemDB[0 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-2)){
Line2.text = "-----------------------";
}
else {
Line2.text = Player.Inventory[1+CurrentScroll].amount + " units of " + Player.Inventory[1+CurrentScroll].name;
ResSp2.sprite = IDB.itemDB[1 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-3)){
Line3.text = "-----------------------";
}
else {
Line3.text = Player.Inventory[2+CurrentScroll].amount + " units of " + Player.Inventory[2+CurrentScroll].name;
ResSp3.sprite = IDB.itemDB[2 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-4)){
Line4.text = "-----------------------";
}
else {
Line4.text = Player.Inventory[3+CurrentScroll].amount + " units of " + Player.Inventory[3+CurrentScroll].name;
ResSp4.sprite = IDB.itemDB[3 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-5)){
Line5.text = "-----------------------";
}
else {
Line5.text = Player.Inventory[4+CurrentScroll].amount + " units of " + Player.Inventory[4+CurrentScroll].name;
ResSp5.sprite = IDB.itemDB[4 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-6)){
Line6.text = "-----------------------";
}
else {
Line6.text = Player.Inventory[5+CurrentScroll].amount + " units of " + Player.Inventory[5+CurrentScroll].name;
ResSp6.sprite = IDB.itemDB[5 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-7)){
Line7.text = "-----------------------";
}
else {
Line7.text = Player.Inventory[6+CurrentScroll].amount + " units of " + Player.Inventory[6+CurrentScroll].name;
ResSp7.sprite = IDB.itemDB[6 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-8)){
Line8.text = "-----------------------";
}
else {
Line8.text = Player.Inventory[7+CurrentScroll].amount + " units of " + Player.Inventory[7+CurrentScroll].name;
ResSp8.sprite = IDB.itemDB[7 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-9)){
Line9.text = "-----------------------";
}
else {
Line9.text = Player.Inventory[8+CurrentScroll].amount + " units of " + Player.Inventory[8+CurrentScroll].name;
ResSp9.sprite = IDB.itemDB[8 + CurrentScroll].itemsprite;
}
if (CurrentScroll > (Player.Inventory.Count-10)){
Line10.text = "-----------------------";
}
else {
Line10.text = Player.Inventory[9 + CurrentScroll].amount + " units of " + Player.Inventory[9 + CurrentScroll].name;
ResSp10.sprite = IDB.itemDB[9 + CurrentScroll].itemsprite;
}