hii all…
I want to load scripts in assets bundle which is component of the gameobject…
But i failed to load those scripts. I have read the documnets given : http://docs.unity3d.com/Manual/scriptsinassetbundles.html
I have tried this like :
//www = WWW.LoadFromCacheOrDownload ("file://E:/HTML5 Testcase/New Unity Project/Resources.unity3d", 1);
www = WWW.LoadFromCacheOrDownload ("localpath/sample.unity3d", 1);
// Wait for download to complete
yield return www;
if(www.error != null)
{
Debug.Log(www.error);
yield break;
}
if(www.error != null)
{
throw new UnityException("WWW download had an error : " + download.error);
}
// Load and retrieve the AssetBundle
AssetBundle bundle1 = www.assetBundle;
bundle1.LoadAllAssets();
// Load the TextAsset object
TextAsset txt = bundle1.LoadAsset("Assembly-CSharp.dll", typeof(TextAsset)) as TextAsset;
Debug.Log ("Txt : " + txt);
if( txt!= null )
{
// Load the assembly and get a type (class) from it
var assembly = System.Reflection.Assembly.Load(txt.bytes);
var type = assembly.GetType("MyClassDerivedFromMonoBehaviour");
//Instantiate a GameObject and add a component with the loaded class
GameObject go = new GameObject();
go.AddComponent(type);
Debug.Log("Loaded.. ");
}
But txt is coming null.
What is the problem with this script. please help me guys.
Thanks.