Hey everyone,
I’m trying to reference two objects in an array, then get their respective individual values to decide whether or not the if statement below should run on them.
The first debug.log properly prints the names (waterfallScript.name) of both objects, but the second debug.log after the if statement only prints the name of the first.
The rest of the code (the transform and coroutine) only work on the first one as well.
It’s worth noting that altering the first object does affect the second.
It’s like the second object gets lost somehow once I go into the if statement.
public void Waterfalling()
{
foreach (GameObject waterfalls in _player.waterFalls)
{
var waterfallScript = waterfalls.GetComponent<Waterfall>();
Debug.Log(waterfallScript.name);
if (!waterfallScript.frozen && waterfallGo && !_player.isTurning)
{
Debug.Log(waterfallScript.name);
transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y + fallSpeed);
StartCoroutine(WaterfallTimer());
}
}
}
Thanks for reading, hopefully someone knows what’s going on.