Unity-CSharp-Mod icon indicating copy to clipboard operation
Unity-CSharp-Mod copied to clipboard

Non Monobehaviour scripts

Open z3t0 opened this issue 9 years ago • 4 comments
trafficstars

I seem to have hit a wall, if we only use MonoBehaviour scripts (Moddable) then how would we go about creating classes and we want to create multiple instances of?

For example,

public class Block{
  string name;
  public Block(string name)
{
 this.name = name;
}
}

And then in another script:

Block block = new Block();

This would fail if Block inherited MonoBehaviour as monobehaviour scripts cannot be "instantiated". I think the limitation for this lies within System.Activator.CreateInstance, but haven't figured out a work around yet.

z3t0 avatar Jul 11 '16 03:07 z3t0

This seems to be a common issue and I have also created a similar issue

z3t0 avatar Jul 11 '16 04:07 z3t0

System.Activator.CreateInstance(type, param1, param2, param3 ...)

Seems to be work, now just need to find a nice way to integrate this solution in an intuitive way!

z3t0 avatar Jul 11 '16 04:07 z3t0

This is just a thought but it might work by simply removing the MonoBehaviour on Moddable

z3t0 avatar Jul 11 '16 09:07 z3t0

Hmm actually nevermind, I think it should work if we just ignore the non mono scripts...

z3t0 avatar Jul 11 '16 10:07 z3t0