I'm trying to replicate MonoBehaviour
of the Unity 3D engine. I'm using monodevelop on Linux, and most testing will be done in Windows Unity 3D engine editor
.
more about MonoBehaviour.Update
can be read here
I want to invoke the Update
method on all types which inherit from MonoBehavior
every 10ms.
this is how I'm doing with Start
using System;
using System.Reflection;
public class MonoBehaviour{
public static void Main (){
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types) {
if (type.IsSubclassOf(typeof(MonoBehaviour))){
System.Reflection.MethodInfo mInfo = type.GetMethod ("Start", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null); // it is run 2 times
if (mInfo != null) {
ConstructorInfo ctor = type.GetConstructor (new Type[] { });
if (ctor != null) {
object inst = ctor.Invoke (new object[] { });
mInfo.Invoke (inst, new object[] { });
}
}
}
}
}
}
class example : MonoBehaviour{
void Start(){
// this works perfectly
Console.WriteLine ("HelloWorld");
}
void Update(){
// I want this to be run every 10 ms
Console.WriteLine ("HelloinUpdate");
}
}