- Home /
Importing assets
Hi. I got stuck importing my spaceship to unity. I did import it but I cannot add javascript to it. Anyway, let me tell you exactly what I did and want to be done so you understand me better:
I created a spaceship in Maya for my spaceshooter game. I saved it in a map called SpaceshipMap along with the textures I created in photoshop. Also when I saved the spaceship in the SpaceshipMap there was also a map named .MayaSwatches. I don't know what its for but I suppose it doesn't matter. So I got this SpaceshipMap; in it, it is the maya file, 5 photoshop files, and the map named mayaswatches. I copy this whole map and paste it into my unity project assets folder. Then I got it in unity. In the projects part.
It is there as a map. I open the map and in there is another map where my UV mapping in maya is. Theres also a Spaceship Prefab and in that prefabs its all the objects I used to create my spaceship in maya. Then at last there is my 5 photoshop files, shown up as images.
Now my question is: How do I add a javascript to my Spaceship Prefab, so that I can drag it out in the scene (Hierarchy) later on and start to script in it?
Thanks in advance//Ticklebear
Answer by Ben 14 · Nov 04, 2010 at 04:20 PM
You can't add a component directly to a prefab in the project pane. Instead, instantiate the prefab in the scene (drag and drop it into the scene view), then add your scripts and components unto that scene object. Unity will tell you that you are losing the prefab connection, which is fine. Once you're satisfied with your setup, hit the Apply button in the inspector pane to update the original prefab with your new setup.
[edit, after checking] This won't work on mesh assets, however, because these are imported assets and not user-created prefabs, so you cannot modify them. In this case what I usually do is:
- create an empty gameobject in the scene
- add the mesh instance as a child of that gameobject
- equip the gameobject with the scripts and components you need
- create a new prefab in the project pane
- drag and drop your gameobject from the hierarchy pane unto the new prefab in the project pane
Hope this helps, Ben
Here's the starting point for constructing game objects from models and scripts in a scene: http://unity3d.com/support/documentation/$$anonymous$$anual/Creating%20Scenes.html
Since it sounds like you're new to Unity, you can't go wrong by reading EVERYTHING in the manual and reference guide.
$$anonymous$$y bad, there's no Apply on a modified mesh instance. AFAI$$anonymous$$, if you want to create an equiped prefab you've got to use an instance of the mesh as a child to another gameobject, which you may then "save" into a new prefab. Editing the answer...
Thanks, thats something I think I will be able to do :P I was thinking of something similar to that, I tried it aswell but I didn't get long before I got stuck but I will follow you 1-5 list and hopefully I'll make it. Cheers
One last thing, $$anonymous$$d explaining how to add a mesh instance as a child to my empty gameobject?
Simply drag the mesh from the project pane over your gameobject name in the hierarchy view until it highlights the name. If you then release the mouse button, a new gameobject will be created with the mesh as a child of the parent object in the hierarchy.
Your answer