I'm creating a script to dynamicly load a menu with buttons. On every button there is a script that need to be run when the button has been clicked. For the button there is a prefab where the script in enabled on. After instantiating the prefab the script on it has been disabled. When I manually enable it by code it does nothing. When enabling the script using the editor it does wor.
My code for generating the buttons on my menu looks like:
foreach (BuildingModel model in models)
{
GameObject tempButton = Instantiate(buttonPrefab);
PlaceObjectToScene script = tempButton.GetComponent<PlaceObjectToScene>();
script.objectName = model.modelLocation + "/" + model.modelName + ".fbx";
script.gameObject.SetActive(true);
script.enabled = true;
tempButton.transform.SetParent(horizontalLayoutGroup.transform);
}
I searched on the internet for some answers and found forum thread with the same issue but non of the sollutions works in my situation. Can someone help me how to enable the script that is default enabled on the prefab?
disabled. \$\endgroup\$Assets -> Export Packageand upload it onDropboxor somewhere. There's no error in this code, I'll take a look. \$\endgroup\$