简体   繁体   中英

No Method Exception on a method that exists

I am attempting to locate a varible in an array, as it was taken originally from the array, but in UnityScript this is not as straighforward as I hoped.

Here is my code for finding the index:

function nextArea() {
    var tmp = Array.IndexOf(areas, currentArea);
    tmp++;
    currentArea = areas[tmp];
    initNewArea();
}

Yet whenever I run it in Unity I get this error:

MissingMethodException: UnityScript.Lang.Array.IndexOf
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.ProduceExtensionDispatcher ()
Boo.Lang.Runtime.DynamicDispatching.MethodDispatcherFactory.Create ()
Boo.Lang.Runtime.RuntimeServices.DoCreateMethodDispatcher(System.Object target, System.Type targetType, System.String name, System.Object[] args)
Boo.Lang.Runtime.RuntimeServices.CreateMethodDispatcher (System.Object target, System.String name, System.Object[] args) 

If you can fix it and have a github account I've opened an issue here: GitHub

Probably you want like this:

var arr = new System.Collections.ArrayList ();

// Add elements
arr.Add ("Hello");
arr.Add("World");

Debug.Log(arr.IndexOf("World"));

You can also try System.Collections.Generic.List<T> , it also contains IndexOf function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM