unity3d - When I give a 'function' type to onclick, it show me the exception InvalidCastException: Cannot cast from source type to destination type -
now i'm using uieventlistener add clicker.when write in 1 file, works right.like this: uieventlistener.get(popbutton).onclick = showpop;
but when wrote 2 seprate files gives me error.first file:
public class adapter{ var grid:gameobject; function additems(data:list.<printitem>, prefab:gameobject, func:function){ for(var i:int=0;i<data.count;i++){ var gameobject:gameobject = nguitools.addchild(grid, prefab); uieventlistener.get(gameobject).onclick = func; } } }
second file:
//i use funtion adapter.additems(list, go[0], hidepop); //the hidepop var hidepop:function = function(){ switchpopmenu(false); };
when run unity give me error
invalidcastexception: cannot cast source type destination type. adapter.additems (system.collections.generic.list`1 data, unityengine.gameobject prefab, icallable func) (at assets/scripts/yhj/tools/adapter.js:12)
try using eventdelegate.add(obj.onclick, func);
. direct assignment may cause issues.
Comments
Post a Comment