- Home /
duplicate a prefab then change the model?
most of the assets that i am using are of a basic sort of model , and use then same scripts. i can drag the model to the screen then spend time adding all the scripts and make these a prefab, which takes time with about 40 differnt models were only 1 or two things need changing in the scipts public part.
what i would like to do is place model add all the scripts then make this a prefab. then duplicate the prefab and change the model, is this possible ?
Answer by ScroodgeM · Jul 30, 2012 at 12:46 PM
i don't know way to easy move configured component from one object to another with saving target's configured components... but...
i found an easy way to create a preconfigured components on gameobjects. script below makes a menu with fast adding preconfigured rigidbody to object. you can use this way to add any preconfigured component. also, you can do it in runtime (just use method's content in runtime script)
also, don't forget that you can set default values for monobehaviours in script. then script will add with these default values.
using UnityEditor; using UnityEngine; using System.Collections; public class FastMenu : MonoBehaviour {
[MenuItem("UnityAnswers/Add Preconfigured Rigidbody")]
static void AddPreconfiguredRigidbody()
{
GameObject go = Selection.activeGameObject;
if (go)
{
Rigidbody rb = go.GetComponent<Rigidbody>();
if (!rb) { rb = go.AddComponent<Rigidbody>(); }
rb.mass = 100;
rb.drag = 0.5f;
rb.angularDrag = 0.5f;
rb.constraints = RigidbodyConstraints.FreezeRotation;
}
}
}