I’m having trouble figuring out how to access a specific script element (seen near the cursor in the picture). Do I need to create a foreach loop to get at this variable? All I want to do is add more health potions via an onTriggerEnter script attached to a box, but I can’t seem to figure out how to access it.
A more secure way to get the script would be using Linq. This way it can be whatever element in the list, assuming BottomActionbarSlots is a list and not an array.
For this solution you have to add using System.Linq; in the using declaration of your script.
void OnTriggerEnter(Collider other)
{
if (other.tag == "YourTag")
{
ActionBars bars = other.GetComponent<ActionBars>();
HealthPotion potion = bars.bottomActionbarSlots.FirstOrDefault(i => i.item is HealthPotion).item as HealthPotion;
++potion.YourVariableWithTheNumberOfPotions;
}
}
I haven’t tried it as I don’t have the rest of the classes but it should work.