- Home /
How to call same method on a list of gameobjects based on index/name
I am hoping to create a function that takes in an index and determine which function to call on a list of objects, something logically similar to
delegate void MyDelegate();
void CallMethodOnObjects(int index, GameObject[] objs) {
MyDelegate del;
switch (index) {
case 0: {
del = SomeMethod;
break;
}
case 1: {...}
default: {...}
}
foreach (GameObject obj in objs) {
obj.GetComponent<SomeClass>().del();
}
}
I know you definitely cannot do this with delegate, so is there a possible walkaround for this situation (so that I do not need to check the index every time I operate on a single GameObject)
Edit: Since I am creating a bullet hell game, better performance is highly anticipated for this function.
Comment
Your answer
Follow this Question
Related Questions
Multiple Method Calls 1 Answer
Why does this run it's "super" method? 1 Answer
InvokeRepeating can't call method 3 Answers
best map creation method 0 Answers
Delegate bug, or intended behaviour? 0 Answers