Question by
unity_bJkbi0kaeUn_TQ · Feb 02, 2021 at 04:14 AM ·
arraystimerinventory systemlooping
Need help looping through an array.
Currently, I have two scriptable objects that act as inventories to store items. One is called equipment, and the other is called current weapon. I currently have a set up where after a bar representing time has been filled to the max, the game takes the first item in your equipment slot, and gives it to the current weapon slot. Then when the item in current weapon has been used, or taken away, the bar will restart and give the the first item again at the filled point.
My question is, how do I loop through the array based on this timer, so that after the first item is passed and used, the second item in the array will then be passed into the current weapon slot? This is the current script I'm working with:
public class Bar : MonoBehaviour
{
public GameObject bar;
private Runner runner;
public InventoryObject equipment;
public InventoryObject currentWeapon;
public int time;
// Start is called before the first frame update
void Start()
{
runner = GetComponent<Runner>();
AnimateBar();
}
// Update is called once per frame
void Update()
{
CheckSlot();
if (currentWeapon.GetSlots[0] == null && time == 0)
{
AnimateBar();
}
}
public void AnimateBar()
{
LeanTween.scaleY(bar, 1, time).setOnComplete(GiveWeapon);
}
public void GiveWeapon()
{
if (equipment.GetSlots[0] != null)
{
currentWeapon.GetSlots[0] = equipment.GetSlots[0];
}
else
{
Debug.LogError( "Equipment slot 0 is null");
}
}
public void CheckSlot()
{
if (currentWeapon.GetSlots[0] == null)
{
time = 0;
}
}
}
Any help would be apreciated.
Comment