- Home /
How to add a script to an imported object
Currently we are working on a project for our school.
I've added a few 3D models that where made by blender and 3DSMAX. But when I try to add script on it it doesn't doe anything. If I add the script on a cube (element of Unity) the script is working.
Is it possible to add a script to a model that was created outside Unity?
Answer by Digitalos · Jun 13, 2010 at 05:28 PM
You add scripts to meshes in much the same way as any other object and under the same conditions. There are a few things you could check:
1) Make sure the object is in your project view. 2) Try adding the script from the Component->Scripts menu as well as dragging it from the project. 3) If you are trying to construct a prefab using the mesh, it's certainly recommended to create a new GameObject in your scene, and then add the mesh object as a child under that. The reason for this is that later when you wish to manipulate the object or change it in any way, it doesn't interfere with the other components on the parent object, so you can easily swap visualisations in/out without messing anything up. Anyhow, it's worth trying this and adding the script directly to the parent and seeing if that is successful for you.
Answer by KvanteTore · Mar 26, 2010 at 10:33 AM
It is certainly possible, and adding scripts to an object with a custom mesh renderer or skinned mesh renderer should not be different from adding scripts to an object with one of the basic mesh renderers supplied with unity.
Could it be that you have not added the object to the scene, and that it is sitting in the project view? I strongly suggest you go through the tutorials to get a better understanding of how unity works.
I'm sure that the object is in the scene. If I change the name of my function to Update the script runs.
You have to name your method Update()
for it to be run automatically every frame. If you call it FixedUpdate()
, it will be called every fixed-update frame, that is every frame that advances the physics. For a complete list of methods that are called for various events, see the $$anonymous$$onoBehaviour documentation, http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$onoBehaviour.html