- Home /
Question by
sandro · Jun 24, 2012 at 06:14 PM ·
prefabvariablepublic variableapply
how to make a variable in a script that do not apply to all prefab istances
hi, there is a way to make a public variable in a script that when setted doesn't aplly to all prefabs?
for istance: I have a prefab with a script with field "name", if I put a string inside and I do some modification to the prefab I don't want this field to be applied to every prefab instance. There is a specifica marker to put in the script or is just not supposed to work in this way?
thanks
Comment
Answer by hijinxbassist · Jun 24, 2012 at 06:28 PM
That is naturally how it works(all fields applied to any instance that has this component). To prevent the field from changing a Clone you can add a boolean called clone
public var clone:boolean;
Then when you set the name of the object to the name field just add a conditional
function Start()
{
if(!clone)gameObject.name=name;
}
function Clone() //when you instantiate the clone, set clone to true on that instance
{
var instance=Instantiate(gameObject,Vector3.zero,Quaternion.identity);
instance.GetComponent(MyScript).clone=true;
}