(C#) I want to apply an operation on all three of the Vector3’s axes, x, y and z. Is there any way I can do it without copy-pasting it three times?
I expected the vector to be IEnumerable but it isn’t, so I can’t use foreach.
Vector3’s xyz variables are simply floats in a struct. So no you can’t use IEnumerator and foreach on them.
What’s the problem with performing the operation 3 times? I mean, even if foreach worked, that would still be 3 operations being performed.
Vector3 does however have a public indexer that you can access:
Vector3 v3 = new Vector3();
for (int i = 0; i < 3; i++)
{
v3 *= Random.Range(0f, 100f);*
}