Help understanding loops with arrays.
I'm trying to create a system where one object has an array of 1 item, and after a certain amount of time, it takes 1 object from the other array and puts it on its own. Then once that object has been taken out, the timer will start again, and then take the next item from the other array. It will keep doing this until it has gone through all the items in the other array, then restart again at the first object.
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;
}
}
}
This is what my current script looks like. I'm currently stuck at my GiveWeapon function, and how I can loop through the array, but in different intervals.
Your answer
Follow this Question
Related Questions
For Loop looping out of Loop Condition 1 Answer
Unity is freezing and I cannot figure out why 1 Answer
Need help looping through an array. 0 Answers
C# noob question (array realated) 1 Answer
Print quest into quest log 0 Answers