Hello,

On all my playable gameObjects (Tank, Car, Boat) that are prefabs I have an unique script for its control:

Prefab----Controlscript

Tank      -    Tank.cs
Car       -    Car.cs
Boat      -    Boat.cs

On all these prefabs the control script is disabled to prevent unneccessary calculations when placing it on the leveleditor.

When the level is played, then the control-script should be enabled by a script called Spawner.cs that instantiates the objects from the saved positions.

However, when different vehicles were placed, the instantiated objects have not the same control scripts.

GameObject entityClone = Instantiate(entity,transform.position,transform.rotation) as GameObject;
entityClone.GetComponent(entityClone.name).enabled = true;

But I get an error: Type UnityEngine.Component does not contain a definition for enabled and no extension method enabled' of type UnityEngine.Component could be found (are you missing a using directive or an assembly reference?)

Components can’t be enabled / diabled. Behaviours can. MonoBehaviour is derived from Behaviour and Behaviour is derived from Component. So you have to cast the return type of GetComponent to at least Behaviour but in most cases you would simply use MonoBehaviour:

MonoBehaviour script = (MonoBehaviour)entityClone.GetComponent(entityClone.name);
script.enabled = true;