2
我使用Unity3D 4.2,並有一個按鈕來觸發此:Unity3D字符串插入陣列
function SubmitMove()
{
p1cube = new Array();
p2cube = new Array();
var allCubeList = GameObject.FindGameObjectsWithTag("cube");
for(var allCube: GameObject in allCubeList)
{
if(allCube.GetComponent(CubeARDP).cubeState == "1")
{
p1cube.Push(allCube.name);
}
else if(allCube.GetComponent(CubeARDP).cubeState == "2")
{
p2cube.Push(allCube.name);
}
}
}
所以p1cube.Push(allCube.name);
如何給我一些錯誤:
MissingMethodException: System.String[].Push
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)
Boo.Lang.Runtime.RuntimeServices+<Invoke>c__AnonStorey15.<>m__9()
Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)
Boo.Lang.Runtime.RuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args)
UnityScript.Lang.UnityRuntimeServices.Invoke (System.Object target, System.String name, System.Object[] args, System.Type scriptBaseType)
axisrotateDynamicParenting.SubmitMove() (at Assets/component_tested/axisrotateDynamicParenting.js:468)
axisrotateDynamicParenting.OnGUI() (at Assets/component_tested/axisrotateDynamicParenting.js:285)
任何想法是怎麼回事??我查看了Unity腳本參考,無論我做什麼似乎都可以。任何幫助都會很棒。謝謝!
如何特別添加JS Array?我只是'var p1cube:String [];'聲明數組時。 – sooon
@sooon:如果我不得不猜測......'var p1cube:Array;'。但我從來沒有見過Unity Script,所以這就是它 - 猜測。 :P – cHao
我將我的數組聲明爲:'var p1cube = new Array([]);'它起作用。我從[this]發現瞭解決方案(http://answers.unity3d.com/questions/12785/is-there-a-way-to-define-arrays-and-objects-litera.html)。感謝您的洞察@cHao,您拯救我的一天:) – sooon