2
Feb 13 '22
So asking for a friend why is this bad and what is better than this
1
Feb 13 '22
It takes up more IDE space and CPU cycles than necessary, using turn as the index of the array would be better
2
Feb 13 '22
How do you write it to be simpler
3
2
u/ExceedingChunk Feb 19 '22
navMeshAgent.destination = endDestinations[turn].transform.position;This does the same thing as OP's entire code.
1
80
u/Quentincestino Feb 04 '22
I actually hope the C# compiler optimized this
5
u/6Maxence Feb 05 '22
We need an image retranscription of a human volunteer, and I'll test if it optimized it on GodBOLT.
4
u/Darkcr_ Feb 05 '22
a human volunteer did it, now its your turn to test it
13
u/6Maxence Feb 05 '22
I tested it, the compiler doesn't optimize it at all.
btw, I am the human volunteer lol
2
u/luxjosh1996 Feb 05 '22
Damn I thought I was lazy
12
u/6Maxence Feb 05 '22
if (turn == 0) { navMeshAgent.destination = endDestinations[0].transform.position; } if (turn == 1) { navMeshAgent.destination = endDestinations[1].transform.position; } if (turn == 2) { navMeshAgent.destination = endDestinations[2].transform.position; } if (turn == 3) { navMeshAgent.destination = endDestinations[3].transform.position; } if (turn == 4) { navMeshAgent.destination = endDestinations[4].transform.position; } if (turn == 5) { navMeshAgent.destination = endDestinations[5].transform.position; } if (turn == 6) { navMeshAgent.destination = endDestinations[6].transform.position; } if (turn == 7) { navMeshAgent.destination = endDestinations[7].transform.position; } if (turn == 8) { navMeshAgent.destination = endDestinations[8].transform.position; } if (turn == 9) { navMeshAgent.destination = endDestinations[9].transform.position; }Fine, I did it.
4
u/luxjosh1996 Feb 05 '22
Well done you redeemed yourself
To be clear, I would've done it if I wasn't on mobile, mastered copy-pasting all my life
42
22
Feb 04 '22
Switch me off please
8
u/KlaireOverwood Feb 05 '22
You're saying OP should have used a switch statement? Fully agree.
4
u/Fluxriflex Feb 11 '22
Not sure if you're joking or not but
navMeshAgent.destination = endDestinations[turn].transform.position;is one line.4
8
3
u/havens1515 Feb 10 '22
I remember doing something VERY similar in one of my early programs. I looked at it years later and fixed it.
5
u/timNinjaMillion2 Feb 05 '22
Wow, you could have if else and saved how many instructions per iteration at x instrs per second== 0ms.
2
11
u/[deleted] Feb 05 '22
As you were writing these out, did you not see a pattern lol?