void AddNewObjective() { Array values = Objectives.GetValues(typeof(Objectives)); Objectives randomObjective = (Objectives)values.GetValue(UnityEngine.Random.Range(0, values.Length)); // var randomObjective = Objectives.MoveToArea; switch (randomObjective) { case Objectives.MoveToArea: objectiveManager.AddObjective(gameObject.AddComponent <MoveToArea>()); break; case Objectives.ActivateTarget: objectiveManager.AddObjective(gameObject.AddComponent <ActivateTarget>()); break; case Objectives.SurviveLasers: objectiveManager.AddObjective(gameObject.AddComponent <SurviveLasers>()); break; case Objectives.ActivateSafeZone: objectiveManager.AddObjective(gameObject.AddComponent <ActivateSafeZone>()); break; } }