|
oksy so I am creating a script to shuffle close targets here is my code however I get an error "Argument is out of range. Parameter name: index" any help?
(comments are locked)
|
|
The problem is that you never actually assign anything to 'targets'! Which means that index '0' will be out of range, because targets is empty. You need to have a line in there somewhere which goes like- before you try to access any of its members. Also, what is this line doing in your FindEnemiesInSphere function? That really shouldn't be there. I don't think you understood what the point of that method was when I wrote it for you earlier. the list targets does not get any new transforms. do you know why that is?
Nov 09 '11 at 01:54 AM
Babilinski
I just explained it! What part of my post can't you understand?
Nov 09 '11 at 03:02 AM
syclamoth
I understand all of it. When I hit play and hit the button it still says 0
Nov 09 '11 at 03:08 AM
Babilinski
Can you post your 'Start' function? The problem here is that it should be assigned instantaneously- if you check for enemies when there are none, and then look at the result of that check later on when there are enemies around, it'll still show zero enemies until you update it again! You need to put the line in every time you want to use it.
Nov 09 '11 at 03:42 AM
syclamoth
I guess the loop should be inside
Nov 09 '11 at 04:31 AM
Bunny83
(comments are locked)
|

I've reformatted your code because it was really hard to see what belongs to what.
As you can see you don't call
FindEnemiesInSphereanywhere except in the function itself!!!! This would lead to a Stack overflow because you would recursivly call the function. Good for you that you don't call the function at the moment, but it should be called (after you fixed it of course) or yourtargets- List will stay empty like syclamoth said.I get the feeling that @Babilinski is fundamentally not understanding the point of that function (which I wrote earlier today, as a solution to a different problem). The bit in the middle which calls the function inside itself is an addition to my script, which kind of screws everything up!
Ok, just to keep the information chain:
http://answers.unity3d.com/questions/184053/targeting-multiple-enemys.html
(i found it in your answers ;))