in my GameManager I have to instantiate enemies. I did a class that does not inherit from MonoBheaviur to be able to pass certain parameters. Code (csharp): Enemie enemie = new Enemie(startWaypoint.neighbors, gameObescr ,0.5f); enemies.Add(enemie); the parameters are: the route of waypoints that the enemy must travel, the game Object that figuratively represents the enemy, is the speed of walking. Below is the Enemy class: Code (csharp): public class Enemie { public List<Cell> waypoints; public Transform enemie; public float velocity; public Enemie(List<Cell> waypoints, Transform enemie, float velocity) { this.waypoints = waypoints; this.enemie = enemie; this.velocity = velocity; enemie.transform.position = waypoints[0].floor.transform.position; } } This class has a coroutine function that I call in the previous script that is used to make it walk along the path. I noticed, however, that within this function I should call another coroutine but not inheriting from mono I can not do it. How could I do?
Coroutines are a part of MB, no way around it. Do your coro in the manager, if you explain what your doing with said coro we can maybe give you another solution.
There's really no reason to avoid using MonoBehaviour for your class. The "trick" to being able to pass initialization to it is pretty simple: Just deactivate the gameObject after instantiating it, set some values on the script, then enable the game object. For example: Code (CSharp): var theGameObject = Instantiate(prefab); theGameObject.SetActive(false); var ctrl = theGameObject.GetComponent<MyController>(); // Set the values the script will need in its Start call. ctrl.InitialConfiguration(x, y, z); // The script's "Start" method will be called some time after SetActive(true). theGameObject.SetActive(true);