- Home /
Creating GameObject from asset.
hi everyone. im actually working in some project and i need to know how can i create a new gameobject directly from an asset using javascript. I dont know exactly how many gameobject ill create beacuse i dont know how many assets i have. that number depends of variables of the game. i just have the route and the name of the assets. thank you and i hope you can understand. this isnt my native language.
Answer by kag359six · Nov 28, 2012 at 11:09 PM
Are your assets in a folder called "Resources"? It won't work otherwise. You code seems fine though... are you getting errors?
Answer by santiiiii · Nov 28, 2012 at 10:54 PM
im doing something like this..
for(var i = 0; i < cuerpos.length ; i++)
{
cuerposObjects[i] = Resources.LoadAssetAtPath(cuerpos[i], typeof(GameObject)) as GameObject;
Instantiate(cuerposObjects[i],Vector3(1,1,1),cuerposObjects[i].transform.rotation);
}
cuerposObjects[] its a array of GameObjects. cuerpos[] its an array of Strings. the routes of the objects.
Answer by santiiiii · Nov 28, 2012 at 11:22 PM
yep, im getting this error..
NullReferenceException: Object reference not set to an instance of an object PressButtonDer.Start () (at Assets/myScripts/PressButtonDer.js:20)
but, no, my asset it isnt in that folder ill create it and try that way. thank you.
Your answer
Follow this Question
Related Questions
Trying to make a simple inventory: 0 Answers
Need help with building system 1 Answer
How to create a professional firstperson-TDgame 1 Answer
Creating a teleportation gun 1 Answer