So I am creating a game which has a build mode where you can place various objects. Some of the prefabs I am instantiating from have scripts that I do not wish to be active during placement, only after placement has been completed. I thought a good solution was to disable these script components by default, and then call a method which activates them upon successful placement.
Perhaps this is not the best approach, and I’m open to alternative suggestions. All input is greatly appreciated.
Here’s my inspector. As you can see I have two scripts which I would like to activate later, both of which have been placed in a list already.
[SerializeField]
List<Component> activateOnBuild = new List<Component>();
private void ActivateComponents()
{
foreach (Component comp in activateOnBuild)
{
comp.enabled = true;
}
}
And here’s my current code. Obviously “comp.enabled = true” doesn’t work but it displays what I’m trying to achieve.